Django迁移:只有部分模型成功迁移到sq

2021-02-25 21:31:38 发布

您现在位置:Python中文网/ 问答频道 /正文

请参阅我的模型和表单(Python2.7)。运行python之后管理.py迁移,只有“公司”和“地区”成功出现在数据库中。在

显示时出错:类型错误需要字符串或缓冲区

我曾经尝试手动添加数据库中的列,但之后表单的数据无法保存到数据库中。在

请帮助查明此迁移问题的原因。提前谢谢你的帮助。在

模型.py

from django import forms
from django.forms import ModelForm
from django.db import models
from dupont.models import Result
from datetime import date
from django.forms import widgets

class Input(models.Model):
    company=models.CharField(max_length=100)
    region=models.CharField(max_length=100)
    supply_chain=models.CharField(max_length=100)
    uom=models.CharField(max_length=100)
    start_date=models.DateField(auto_now=False, auto_now_add=False)
    end_date=models.DateField(auto_now=False, auto_now_add=False)

    def __unicode__(self):
        return self.company

表单.py

^{pr2}$

错误

  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem
ent\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem
ent\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem
ent\base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem
ent\base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem
ent\commands\migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\migration
s\executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=f
ake_initial)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\migration
s\executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\migration
s\migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\migration
s\operations\fields.py", line 62, in database_forwards
    field,
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\backends\
mysql\schema.py", line 43, in add_field
    super(DatabaseSchemaEditor, self).add_field(model, field)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\backends\
base\schema.py", line 384, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\backends\
base\schema.py", line 146, in column_sql
    default_value = self.effective_default(field)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\backends\
base\schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\models\fi
elds\__init__.py", line 710, in get_db_prep_save
    prepared=False)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\models\fi
elds\__init__.py", line 1322, in get_db_prep_value
    value = self.get_prep_value(value)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\models\fi
elds\__init__.py", line 1317, in get_prep_value
    return self.to_python(value)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\db\models\fi
elds\__init__.py", line 1274, in to_python
    parsed = parse_date(value)
  File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\utils\datepa
rse.py", line 60, in parse_date
    match = date_re.match(value)
TypeError: expected string or buffer