我在迁移模型时遇到错误。
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\django\base.py", line 115,
in _execute_wrapper
return method(query, args)
File "C:\Python34\lib\site-packages\mysql\connector\cursor.py", line 507, in e
xecute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 722,
in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 640,
in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.DatabaseError: 1215 (HY000): Cannot add foreign key const
raint
in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 640,
in _handle_result
raise errors.get_exception(packet)
django.db.utils.DatabaseError: Cannot add foreign key constraint
请帮我解决这个错误。在此先感谢!!!
以下是我的模特:
类别模型:
class categories(models.Model) :
id = dbUtils.BigAutoField(primary_key = True)
name = models.CharField(unique=True, max_length=100)
description = models.CharField(max_length=500,blank=True)
Feed模型:
class feeds(models.Model) :
name = models.CharField(max_length=100, blank = True )
country = models.ManyToManyField(countries,related_name='feedcountry')
state = models.ManyToManyField(states,related_name='feedstate')
city = models.ManyToManyField(cities,related_name='feedcity')
feedsMapping模型:
class feedsMapping(models.Model) :
id = dbUtils.BigAutoField(primary_key=True)
feeds = dbUtils.BigForeignKey(feeds, related_name='feedmap')
language = dbUtils.BigForeignKey(languages, related_name='feedmaplanguage')
categories = models.ManyToManyField(categories,verbose_name='feedmapcategories')
title = models.CharField(max_length=100)
country = models.ManyToManyField(countries,related_name='feedmapcountry')
state = models.ManyToManyField(states,related_name='feedmapstate')
city = models.ManyToManyField(cities,related_name='feedmapcity')