@leha78

Как выявить причину ошибки?

Делаю migrate и получаю ошибку. Подключен MySQL

migrate
"C:\Program Files\JetBrains\PyCharm 4.5.4\bin\runnerw.exe" C:\Python\python.exe "C:\Program Files\JetBrains\PyCharm 4.5.4\helpers\pycharm\django_manage.py" migrate C:/DjangoProjects/cosmetic
System check identified some issues:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS.
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, sites, sessions, blog, auth, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying blog.0002_auto_20160108_2257...Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 4.5.4\helpers\pycharm\django_manage.py", line 41, in <module>
    run_module(manage_file, None, '__main__', True)
  File "C:\Python\lib\runpy.py", line 182, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "C:\Python\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:/DjangoProjects/cosmetic\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\core\management\base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\core\management\base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\core\management\commands\migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\migrations\executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\migrations\executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\migrations\migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\migrations\operations\fields.py", line 62, in database_forwards
    field,
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\backends\mysql\schema.py", line 43, in add_field
    super(DatabaseSchemaEditor, self).add_field(model, field)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\backends\base\schema.py", line 384, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\backends\base\schema.py", line 146, in column_sql
    default_value = self.effective_default(field)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\backends\base\schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\models\fields\related.py", line 1951, in get_db_prep_save
    return self.related_field.get_db_prep_save(value, connection=connection)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\models\fields\__init__.py", line 710, in get_db_prep_save
    prepared=False)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\models\fields\__init__.py", line 978, in get_db_prep_value
    value = connection.ops.validate_autopk_value(value)
  File "C:\Python\lib\site-packages\django-1.8.4-py3.5.egg\django\db\backends\mysql\operations.py", line 137, in validate_autopk_value
    raise ValueError('The database backend does not accept 0 as a '
ValueError: The database backend does not accept 0 as a value for AutoField.

Process finished with exit code 1
  • Вопрос задан
  • 655 просмотров
Решения вопроса 1
ну так написано же
ValueError: The database backend does not accept 0 as a value for AutoField.

это значить что в таблице обьявлено поле типа AutoField (это поле Id обычно) котороему автоматически присваивается 0, чего не может быть. покажите обьявление класса таблицы
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы