Does Django's south (migration tool) work for innodb?

后端 未结 4 1061
余生分开走
余生分开走 2021-01-01 04:39
$ py manage.py  migrate turkey
Running migrations for turkey:
 - Migrating forwards to 0001_initial.
 > turkey:0001_initial
 ! Error found during real run of migr         


        
4条回答
  •  盖世英雄少女心
    2021-01-01 05:04

    See also https://code.djangoproject.com/wiki/AlterModelOnSyncDB

    I have had the same kind of error happen to me when working with a mysql setup whose default table storage engine is MyISAM and I wanted to use InnoDB (using the recipe found in above link, we used the post_syncdb signal to trigger the conversion code). However, when using South to create new tables they were first created using MyISAM engine then later converted. I was mistakenly believing InnoDB tables weren't doing what they were supposed to, when those were actually MyISAM; because the table were converted by the signal, any migration error would fail to unapply :-/

    If you need to use or create InnoDB tables where the default is MyISAM, this be solved with:

    # add at the beginning of your migration
    if db.backend_name == 'mysql':
       db.execute('SET storage_engine=INNODB')
    

    or if you do not mind the performance hit:

    # add this to settings.py
    DATABASE_OPTIONS = {
       "init_command": "SET storage_engine=INNODB", # XXX: performance hit...
    }
    

提交回复
热议问题