重复SYNCDB产生不同的结果?

时间:2012-04-08 03:35:03

标签: django django-models

当我运行syncdb时,它给了我一个MySQL 150错误,可能与FK有关。但是,当我反复运行syncdb时,它最终会起作用(下面的整个轨迹)。为什么会这样?

    david-MacBook-Pro$ syncdb
    Creating tables ...
    Creating table jobs_company
    Creating table jobs_job
    Traceback (most recent call last):
      File "manage.py", line 14, in <module>
        execute_manager(settings)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
        output = self.handle(*args, **options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
        return self.handle_noargs(**options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
        cursor.execute(statement)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
        return self.cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
        return self.cursor.execute(query, args)
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
    _mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57e' (errno: 150)")
    david-MacBook-Pro:$ syncdb
    Creating tables ...
    Creating table jobs_jobposition
    Creating table jobs_externaljob
    Creating table jobs_externalsite
    Creating table jobs_sitevisit
    Traceback (most recent call last):
      File "manage.py", line 14, in <module>
        execute_manager(settings)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
        output = self.handle(*args, **options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
        return self.handle_noargs(**options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
        cursor.execute(statement)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
        return self.cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
        return self.cursor.execute(query, args)
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
    _mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57f' (errno: 150)")
    david-MacBook-Pro$ syncdb
    Creating tables ...
    Creating table jobs_application
    Traceback (most recent call last):
      File "manage.py", line 14, in <module>
        execute_manager(settings)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
        output = self.handle(*args, **options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
        return self.handle_noargs(**options)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
        cursor.execute(statement)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
        return self.cursor.execute(sql, params)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
        return self.cursor.execute(query, args)
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
      File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
    _mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_580' (errno: 150)")
    david-MacBook-Pro$ syncdb
    Creating tables ...
    Installing custom SQL ...
    Installing indexes ...
    No fixtures found.

它有效吗?

1 个答案:

答案 0 :(得分:2)

这是有效的,因为没有创建FK。分析生成的SQL以验证错误发生的原因,并根据需要重新排序settings.INSTALLED_APPS