开发者社区> 问答> 正文

django模型同步oracle报错缺失右括号?报错

python版本:3.6.4

django版本 2.0

oracle 11g

执行python manage.py migrate时报错如下:

C:\Python36\lib\site-packages\django\db\models\base.py:309: RuntimeWarning: Model 'books.publisher' wa
s already registered. Reloading models is not advised as it can lead to inconsistencies, most notably
with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_c
ommand_line
    utility.execute()
  File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 347, in execute
    django.setup()
  File "C:\Python36\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python36\lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Python36\lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\mysite\books\models.py", line 20, in <module>
    class Publisher(models.Model):
  File "C:\mysite\books\models.py", line 22, in Publisher
    authors = models.ManyToManyField(Author)
NameError: name 'Author' is not defined

C:\mysite>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, books, contenttypes, sessions
Running migrations:
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Python36\lib\site-packages\django\db\backends\oracle\base.py", line 500, in execute
    return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-00907: missing right parenthesis

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\django\db\migrations\recorder.py", line 55, in ensure_schema
    editor.create_model(self.Migration)
  File "C:\Python36\lib\site-packages\django\db\backends\base\schema.py", line 298, in create_model
    self.execute(sql, params or None)
  File "C:\Python36\lib\site-packages\django\db\backends\base\schema.py", line 117, in execute
    cursor.execute(sql, params)
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers

    return executor(sql, params, many, context)
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Python36\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Python36\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Python36\lib\site-packages\django\db\backends\oracle\base.py", line 500, in execute
    return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-00907: missing right parenthesis

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_c
ommand_line
    utility.execute()
  File "C:\Python36\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python36\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python36\lib\site-packages\django\core\management\base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "C:\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle

    fake_initial=fake_initial,
  File "C:\Python36\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "C:\Python36\lib\site-packages\django\db\migrations\recorder.py", line 57, in ensure_schema
    raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (
ORA-00907: missing right parenthesis)

报错信息如上

其中模型部分脚本:

class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()
    def __unicode__(self):
        return self.name

类似上述模型

请大佬指点!!!

展开
收起
爱吃鱼的程序员 2020-06-06 15:30:24 1143 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        Urlfileds其实也是一个charfileds所以也需要一个最大值 
                    
    
                        <p>NameError: name 'Author' is not defined</p>
    

    逐个排查,先把这个错误解决一下试试

    2020-06-06 15:30:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PostgresChina2018_樊文凯_ORACLE数据库和应用异构迁移最佳实践 立即下载
PostgresChina2018_王帅_从Oracle到PostgreSQL的数据迁移 立即下载
Oracle云上最佳实践 立即下载

相关镜像