Django South-db.alter函数删除null=true blank=true会在mysql中失败

Django South-db.alter函数删除null=true blank=true会在mysql中失败,mysql,django-models,django-south,django-database,Mysql,Django Models,Django South,Django Database,通过删除这两个值,将日期字段从null=True和blank=True更改为required时,db.alter命令出现问题 当注释掉下面的行时,迁移运行不会出现问题 db.alter_column('milestones_milestone', 'date', self.gf('django.db.models.fields.DateField')(default='2011-01-01')) 这将更改列说明,从: 'milestones.milestone': { 'date'

通过删除这两个值,将日期字段从null=True和blank=True更改为required时,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'}),
},

当迁移中保留上述行时,我得到的错误是:

 - 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")
-向前迁移到0002\自动\添加\字段\里程碑\类型\更改\字段\里程碑\日期\添加\字段\ mi。
>里程碑:0002\自动\添加\字段\里程碑\类型\更改\字段\里程碑\日期\添加\字段\ mi
! 在迁移的实际运行期间发现错误!流产。
! 因为您的数据库不支持运行
! 在事务中改变模式的语句,我们有
! 使其在迁移之间处于过渡状态。
! 您*可能*能够通过以下方式进行恢复:=ALTER TABLE`MILESTOMES\U MILESTOMES`DROP COLUMN`type`CASCADE;[]
=更改表'MilestonetTemplate'下拉列'type'级联;[]
! 南方开发商对此感到遗憾,并将
! 喜欢温柔地劝你稍微考虑一下。
! 更容易处理DBMS。
! 注意:导致迁移失败的错误还在后面。
回溯(最近一次呼叫最后一次):
文件“manage.py”,第11行,在
执行\u管理器(全局\u设置)
文件“C:\Python26\lib\site packages\django\core\management\\uuuu init\uuuuu.py”,第438行,在执行管理器中
utility.execute()
文件“C:\Python26\lib\site packages\django\core\management\\uuuu init\uuuuu.py”,第379行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“C:\Python26\lib\site packages\django\core\management\base.py”,第191行,运行于\u argv
self.execute(*args,**选项._dict__;
文件“C:\Python26\lib\site packages\django\core\management\base.py”,第218行,在execute中
输出=self.handle(*args,**选项)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\management\commands\migrate.py”,第109行,在ha中
ndle
忽略重影=忽略重影,
文件“C:\SQE\U Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\\uuuuu init\uuuuu.py”,第202行,在migrate\u应用程序中
success=migrator.migrate\u many(目标、工作计划、数据库)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\migrators.py”,第292行,在migrate\u ma中
纽约
结果=self.migrate(迁移,数据库)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\migrators.py”,第125行,在migrate中
结果=self.run(迁移)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\migrators.py”,第99行,正在运行
返回self.run\u迁移(迁移)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\migrators.py”,第81行,在run\u migrati中
在…上
迁移函数()
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\migration\migrators.py”,第57行,在
返回(λ:方向(orm))
文件“C:\SQE\U Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\Milestomes\migrations\0002\u auto\u添加\u字段\u Milestomes\u类型_
_chg_字段_里程碑_日期_添加_字段_mi.py”,第15行,向前
db.alter\u列('millements\u millestone','date',self.gf('django.db.models.fields.DateField')(默认值为'2011-01-01'))
文件“C:\SQE\U Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\db\generic.py”,第373行,在alter\U列中
self.execute(“ALTER TABLE%s%s;”%(self.quote\u name(TABLE\u name),sql),values)
文件“C:\SQE\u Dashboard\SQE Dashboard mimercha\SQE Dashboard\Dashboard\lib\south\db\generic.py”,执行中的第137行
cursor.execute(sql,params)
文件“C:\Python26\lib\site packages\django\db\backends\util.py”,第15行,执行
返回self.cursor.execute(sql,params)
文件“C:\Python26\lib\site packages\django\db\backends\mysql\base.py”,第86行,在execute中
返回self.cursor.execute(查询,参数)
文件“C:\Python26\lib\site packages\MySQLdb\cursors.py”,第173行,在execute中
errorhandler(self、exc、value)
defaulterrorhandler中第36行的文件“C:\Python26\lib\site packages\MySQLdb\connections.py”
提高errorclass,errorvalue
django.db.utils.DatabaseError:(1265,“第512行“日期”列的数据被截断”)
我正在使用:

南方0.71注:我尝试升级到0.73,发现0.73给了我同样的错误,并在加载旧设备时破坏了我的脚本

Django 1.2.1

python库:MySQLDdb API v2.0兼容,版本603

mysql版本14.14发行版5.1.51,适用于Win32(ia32)


InnoDB存储引擎

我刚刚遇到了相同的错误。在我的例子中,我意外地将列的默认值设置为
datetime.now
,这导致了数据截断


我建议您从模型中删除默认值,设置
auto\u now\u add=True
,然后重新生成迁移文件。

不幸的是,我不再在项目中验证这是否有效,但这对我来说很有意义:)
 - 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")