简体   繁体   English

python manage.py迁移着陆错误

[英]python manage.py migrate landing error

I want to migrate my app "landing" with south I write the following command 我想向南迁移我的应用程序“着陆”,我编写了以下命令

python manage.py migrate landing python manage.py迁移登陆

but it shows the following error 但它显示以下错误

Running migrations for landing: 运行着陆迁移:

  • Migrating forwards to 0003_auto__chg_field_userinput_email2. 迁移到0003_auto__chg_field_userinput_email2。 landing:0001_initial 着陆:0001_initial

FATAL ERROR - The following SQL query failed: CREATE TABLE landing_userinput ( id integer AUTO_INCREMENT NOT NULL PRIMARY KEY, name varchar(120) NOT NULL, email varchar(200) NOT NULL, city varchar(120) NOT NULL, timestamp datetim e NOT NULL) 致命错误-以下SQL查询失败:CREATE TABLE landing_userinputid整数AUTO_INCREMENT NOT NULL主键, name varchar(120)NOT NULL, email varchar(200)NOT NULL, city varchar(120)NOT NULL, timestamp datetim e NOT NULL )

The error was: (1050, "Table 'landing_userinput' already exists") ! 错误为:(1050,“表'landing_userinput'已经存在”)! 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: = DROP TABLE landing_userinput CASCAD E; 也许可以使用以下方法进行恢复:= DROP TABLE landing_userinput CASCAD E; [] []

raise errorclass, errorvalue 引发错误类,错误值

django.db.utils.OperationalError: (1050, "Table 'landing_userinput' already exists") django.db.utils.OperationalError:(1050,“表'landing_userinput'已经存在”)

Please give me suggestions to improve this bug. 请给我建议以改善此错误。

Don't use syncdb and migrate at the same time; 不要同时使用syncdb和进行migrate this will conflict as the initial migration will create a blank table. 这将产生冲突,因为初始迁移将创建一个空白表。

If you have a new app and want to have it managed by south, your sequence of operations is: 如果您有一个新应用,并希望由Southern管理,则操作顺序为:

  1. ./manage.py schemamigration landing --initial -- this creates the initial migration, which creates the tables for the application. ./manage.py schemamigration landing --initial这将创建初始迁移,从而为应用程序创建表。 You only do this once . 您只需执行一次
  2. ./manage.py migrate landing -- this will apply the migration. ./manage.py migrate landing -这将应用迁移。 The first time you do this (with step #1 from above), this will create an empty table in the database. 第一次执行此操作(从上面的步骤1开始),这将在数据库中创建一个空表。

Once you have done the first two steps, whenever you make a change to your model, you run these two commands: 完成前两个步骤后,只要对模型进行更改,就可以运行以下两个命令:

  1. ./manage.py schemamigration landing --auto -- this will create the file that has the changes to your model (the migration). ./manage.py schemamigration landing --auto这将创建对模型进行更改(迁移)的文件。

  2. ./manage.py migrate landing -- this will apply the new migration (this is the same command from above); ./manage.py migrate landing -这将应用新的迁移(与上面的命令相同); and it will affect the changes to your database. 它将影响对数据库的更改。

If you already have an existing application, install south and run syncdb to create south's own database tables, then run ./manage.py convert_to_south yourappname ; 如果您已经有一个现有的应用程序,请安装south并运行syncdb来创建./manage.py convert_to_south yourappname自己的数据库表,然后运行./manage.py convert_to_south yourappname this will do a "fake" migration and set it to the last state of the models. 这将进行“伪”迁移并将其设置为模型的最后状态。 Then, follow the schemamigration yourappname --auto and migrate steps. 然后,遵循schemamigration yourappname --automigrate步骤。

In your case, you have two options: 就您而言,您有两种选择:

  1. Drop the table (as the error suggests). 删除表(错误提示)。 This will get rid of all the data as well. 这也将消除所有数据。 If you are in development, this is the easiest way to get started fresh (you should also use fixtures if you want to provide some default data for your models). 如果您正在开发中,这是重新开始的最简单方法(如果您想为模型提供一些默认数据,则也应该使用固定装置 )。

  2. You can use the --fake option to trick south into thinking the operation has been done already. 您可以使用--fake选项欺骗南方,使您认为操作已完成。 See the documentation for more. 有关更多信息,请参见文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM