我希望将外键的名称从uuid更改为uuid_erp。
要做到这一点,我可以运行如下迁移:
migrations.RunSQL('''
ALTER TABLE result_suppliers
RENAME COLUMN uuid TO uuid_erp;
''')通过这样做,我基本上希望为django进行迁移,并且它在运行makemigrations时什么也不做。
但是,当我运行python manage.py makemigrations时,我看到django正在尝试创建列uuid_erp (已经创建了)。这给出了这样的信息:
You are trying to add a non-nullable field 'uuid_erp' to resultsuppliers without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option: 从医学博士中我看到django:
根据对模型的更改创建新的迁移。
这并不能让我们对如何检测到这些变化有很大的了解。
我的问题有两个方面:
注意:如果我使用makemigrations而不是定制的rename命令,django将删除并重新创建一个uuid_erp,并且uuid中的现有信息将丢失。
发布于 2021-06-23 19:58:22
这听起来是SeparateDatabaseAndState的一个很好的用例。关于如何执行这个这里,有一个很好的例子。
https://stackoverflow.com/questions/65846317
复制相似问题