django 创建mysql失败_创建表时出现Django MySQL错误

我正在用MySQL数据库构建一个django应用程序。当我第一次运行“python manage.py migrate”时,一些表创建得很好,然后出现一些错误。出现的错误是:django.db.utils.IntegrityError: (1215, 'Cannot add foreign key

constraint')

当我运行这个MySQL命令时-SHOW ENGINE INNODB STATUS\G,

我明白了>&gt2015-02-17 14:33:17 7f10891cf700 Error in foreign key constraint of table movie_store/#sql-4f1_66:

FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`):

Cannot resolve table name close to:

(`id`)

完整的回溯是:Creating tables...

Creating table users

Creating table merchant

Creating table celery_taskmeta

Creating table celery_tasksetmeta

Creating table djcelery_intervalschedule

Creating table djcelery_crontabschedule

Creating table djcelery_periodictasks

Creating table djcelery_periodictask

Creating table djcelery_workerstate

Creating table djcelery_taskstate

Creating table post_office_email

Creating table post_office_log

Creating table post_office_emailtemplate

Creating table post_office_attachment

Running deferred SQL...

Traceback (most recent call last):

File "manage.py", line 10, in

execute_from_command_line(sys.argv)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line

utility.execute()

File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv

self.execute(*args, **cmd_options)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute

output = self.handle(*args, **options)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 173, in handle

created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 309, in sync_apps

cursor.execute(statement)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 80, in execute

return super(CursorDebugWrapper, self).execute(sql, params)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute

return self.cursor.execute(sql, params)

File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95, in __exit__

six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 63, in execute

return self.cursor.execute(sql)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute

return self.cursor.execute(query, args)

File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute

self.errorhandler(self, exc, value)

File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler

raise errorclass, errorvalue

django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值