Есть две модели:
class Theme(models.Model):
name = models.CharField(_(u'Название темы вопросов'), max_length=100)
count_question = models.IntegerField(_(u'Количество вопросов в теме'), max_length=5, default=0)
sort = models.IntegerField(_(u'Сортировка'), max_length=3, default=0)
description = models.TextField(_(u'Описание'), max_length=5000, blank=True, null=True)
# локализация
class Meta:
verbose_name = _(u'Тема')
verbose_name_plural = _(u'Темы')
def __unicode__(self):
return self.name
class HistoryTheme(models.Model):
STATUS_CHOICES = (
('0', 'Ошибка'),
('1', 'Пройдено'),
)
user = models.ForeignKey(User, unique=False, db_index=True, verbose_name=_(u'Пользователь'))
theme = models.ForeignKey(Themes, unique=False, db_index=True, verbose_name=_(u'Тема'))
question_first = models.IntegerField(_(u'Начальный вопрос'), max_length=3)
status = models.CharField(_(u'Статус прохождения'), choices=STATUS_CHOICES, max_length=1, default=0)
error_count = models.SmallIntegerField(_(u'Количество ошибок в теме'), max_length=2)
create_at = models.DateTimeField(_(u"Добавлена"), auto_now_add=True)
# локализация
class Meta:
verbose_name = _(u'Запись истории по билету')
verbose_name_plural = _(u'Истории прохождения тестов по билетам')
def __unicode__(self):
return self.status
При создании таблиц в базе через syncdb вылетает ошибка "Cannot add foreign key constraint":
Creating table account_historyticket Traceback (most recent call
last): File
"/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 23,
in <module>
run_module(manage_file, None, 'main', True) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",
line 176, in run_module
fname, loader, pkg_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",
line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",
line 72, in _run_code
exec code in run_globals File "/Users/sergeytarasenko/work/projects/pdd/manage.py", line 10, in
<module>
execute_from_command_line(sys.argv) File "/Library/Python/2.7/site-packages/django/core/management/init.py",
line 399, in execute_from_command_line
utility.execute() File "/Library/Python/2.7/site-packages/django/core/management/init.py",
line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 242, in run_from_argv
self.execute(args, options.dict) File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 285, in execute
output = self.handle(*args, options) File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 415, in handle
return self.handle_noargs(*options) File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py",
line 107, in handle_noargs
cursor.execute(statement) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line
69, in execute
return super(CursorDebugWrapper, self).execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line
53, in execute
return self.cursor.execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/utils.py", line 99, in
exit
six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line
51, in execute
return self.cursor.execute(sql) File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py",
line 124, in execute
return self.cursor.execute(query, args) File "/Library/Python/2.7/site-packages/MySQLdb/cursors.py", line 205, in
execute
self.errorhandler(self, exc, value) File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 36,
in defaulterrorhandler
raise errorclass, errorvalue django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
Process finished with exit code 1
Что я делаю не так?
Django version 1.6.4, python2.7, MySQL 5.6.17