Django postgre migrate error
我将数据库后端从sqlite3更改为postgre。 当我尝试运行迁移时出现错误
1 | MacBook-Pro-Oleg:avtofarm okorablev$ python3 manage.py migrate |
执行的操作:
同步未迁移的应用程序:消息,avtofarm,smart_selects,静态文件,缩略图
应用所有迁移:contenttypes,admin,callboard,auth,sessions
无需迁移即可同步应用:
创建表格......
运行延迟的SQL ...
安装自定义SQL ...
正在运行迁移:
渲染模型状态...完成
应用callboard.0004_auto_20150701_1609 ... Traceback(最近一次调用最后一次):
文件"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py",第64行,执行
return self.cursor.execute(sql,params)
psycopg2.ProgrammingError:列"manufdate"无法自动转换为键入日期
提示:指定USING表达式以执行转换。
上述异常是以下异常的直接原因:
Traceback (most recent call last): File"manage.py", line 10, in
execute_from_command_line(sys.argv) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/init.py",
line 338, in execute_from_command_line
utility.execute() File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/init.py",
line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py",
line 393, in run_from_argv
self.execute(*args, **cmd_options) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py",
line 444, in execute
output = self.handle(*args, **options) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/commands/migrate.py",
line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/executor.py",
line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/executor.py",
line 148, in apply_migration
state = migration.apply(state, schema_editor) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/migration.py",
line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/operations/fields.py",
line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/base/schema.py",
line 484, in alter_field
old_db_params, new_db_params, strict) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/base/schema.py",
line 636, in _alter_field
params, File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/base/schema.py",
line 111, in execute
cursor.execute(sql, params) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py",
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/utils.py",
line 97, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/utils/six.py",
line 658, in reraise
raise value.with_traceback(tb) File"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: column"manufdate" cannot be cast
automatically to type date HINT: Specify a USING expression to
perform the conversion.
模型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | class Zip(models.Model): category = models.ForeignKey(Category,null=True,verbose_name='Категория') subcategory = ChainedForeignKey(SubCategory,chained_field="category", chained_model_field="category", show_all=False, auto_choose=True,verbose_name='Подкатегория') type = models.ForeignKey(Type,verbose_name='Состояние') zipgroup = models.ForeignKey(ZipGroup,null=True,verbose_name='Группа запчастей') ziptype = models.ForeignKey(ZipType,null=True,verbose_name='Вид запчасти') cartype = models.ForeignKey(CarType,null=True,verbose_name='Тип авто') carmodel = models.ForeignKey(CarModel,null=True,verbose_name='Модель транспорта') carbodytype = models.ForeignKey(CarBodyType,null=True,verbose_name='Тип кузова') catalognumber = models.CharField(max_length=100,null=True,blank=True,verbose_name='Номер по каталогу') manufdate = models.CharField(max_length=4,null=True,verbose_name='Год выпуска') title = models.CharField(max_length=100,verbose_name='Заголовок объявления') description = models.TextField(null=True,verbose_name='Описание') price = models.IntegerField(verbose_name='Цена') user = models.ForeignKey(User,verbose_name='Пользователь') creation_date = models.DateTimeField('date published') is_sell = models.BooleanField(default=False) is_active = models.BooleanField(default=True) likes = models.IntegerField(default=0) |
查看迁移代码(适用于包含
删除数据库后,问题解决了,制作了新的数据库,又一次做了迁移和迁移。 但我认为应该是另一种如何在不删除数据库的情况下更好地决定这个问题的方法