通过删除这两个值,将日期字段从null = True和空白= True更改为必需时,db.alter命令出现问题。
当以下行被注释掉时,迁移运行没有问题。
db.alter_column('milestones_milestone', 'date', self.gf('django.db.models.fields.DateField')(default='2011-01-01'))
这应该改变列描述:
'milestones.milestone': {
'date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
},
到
'milestones.milestone': {
'date': ('django.db.models.fields.DateField', [], {default:'2011-01-01'}),
},
如果在迁移中留下上述行,则会收到错误:
- Migrating forwards to 0002_auto__add_field_milestone_type__chg_field_milestone_date__add_field_mi.
> milestones:0002_auto__add_field_milestone_type__chg_field_milestone_date__add_field_mi
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = ALTER TABLE `milestones_milestone` DROP COLUMN `type` CASCADE; []
= ALTER TABLE `milestones_milestonetemplate` DROP COLUMN `type` CASCADE; []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(global_settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 218, in execute
output = self.handle(*args, **options)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\management\commands\migrate.py", line 109, in ha
ndle
ignore_ghosts = ignore_ghosts,
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\__init__.py", line 202, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\migrators.py", line 292, in migrate_ma
ny
result = self.migrate(migration, database)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\migrators.py", line 125, in migrate
result = self.run(migration)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\migrators.py", line 99, in run
return self.run_migration(migration)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\migrators.py", line 81, in run_migrati
on
migration_function()
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\migration\migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\milestones\migrations\0002_auto__add_field_milestone_type_
_chg_field_milestone_date__add_field_mi.py", line 15, in forwards
db.alter_column('milestones_milestone', 'date', self.gf('django.db.models.fields.DateField')(default='2011-01-01'))
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\db\generic.py", line 373, in alter_column
self.execute("ALTER TABLE %s %s;" % (self.quote_name(table_name), sql), values)
File "C:\SQE_Dashboard\SQE Dashboard-mimercha\SQE Dashboard\dashboard\lib\south\db\generic.py", line 137, in execute
cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 15, in execute
return self.cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 86, in execute
return self.cursor.execute(query, args)
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DatabaseError: (1265, "Data truncated for column 'date' at row 512")
我正在使用:
South 0.71注意:我尝试升级到0.73并发现0.73给我带来了同样的错误并在加载旧灯具时破坏了我的脚本。
Django 1.2.1
python库:兼容MySQLDdb DB API v2.0,修订版603
mysql Ver 14.14 Distrib 5.1.51,for Win32(ia32)
InnoDB存储引擎
答案 0 :(得分:1)
我遇到了同样的错误。在我的情况下,我不小心将列的默认值设置为datetime.now
,导致数据截断。
我建议您从模型中删除默认值,设置auto_now_add=True
并重新生成迁移文件。