django 报错求大神指教

迷途小书虫 发布于 2017/03/10 09:57
阅读 240
收藏 0

django执行python manage.py migrate后出现报错

Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: sessions, admin, auth, contenttypes, books, foodsite
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying foodsite.0006_bookfood_num...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
    field,
  File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/schema.py", line 43, in add_field
    super(DatabaseSchemaEditor, self).add_field(model, field)
  File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 384, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 146, in column_sql
    default_value = self.effective_default(field)
  File "/usr/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1626, in get_db_prep_save
    return connection.ops.value_to_db_decimal(self.to_python(value),
  File "/usr/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1602, in to_python
    params={'value': value},
django.core.exceptions.ValidationError: [u"'' value must be a decimal number."]

加载中
0
沧海_Sea
沧海_Sea

'' value must be a decimal number

0
0
听风的小猪
听风的小猪

这个报错是说value值必须是个小数,你debug下看看是不是models里面有字段定义出错

0
迷途小书虫
迷途小书虫

谢谢,问题已经解决了,我把migrations和 数据库的记录迁移记录清空,重新迁移了

 

返回顶部
顶部