为 Django 应用程序进行新迁移,忽略所有其他应用程序模型
Making a new migration for a Django app, ignoring all other app models
我在应用程序 bicycles
的项目中对 Django 模型 Bicycle
进行了模型更改,其中另一个不相关的应用程序 cars
有一个模型 Car
有模型变化,没有伴随的 makemigrations。 cars.Car
的开发者不可用,我无法更改他们的源代码,但我仍然需要为 bicycles.Bicycle
进行新的迁移。
这在 Django 2.2 中完全可行吗?当我 运行 makemigrations bicycles
,我得到这个:
You are trying to add a non-nullable field 'year' to car 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:
正如我所说,bicycles
应用程序与 cars
完全无关,所以我觉得我应该能够为 bicycles
应用程序进行迁移 只有?
我通过将 cars/migrations/__init__.py
重命名为其他名称解决了这个问题,这样 Django 就无法找到它,我可以按预期进行 bicycles
迁移。
我在应用程序 bicycles
的项目中对 Django 模型 Bicycle
进行了模型更改,其中另一个不相关的应用程序 cars
有一个模型 Car
有模型变化,没有伴随的 makemigrations。 cars.Car
的开发者不可用,我无法更改他们的源代码,但我仍然需要为 bicycles.Bicycle
进行新的迁移。
这在 Django 2.2 中完全可行吗?当我 运行 makemigrations bicycles
,我得到这个:
You are trying to add a non-nullable field 'year' to car 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:
正如我所说,bicycles
应用程序与 cars
完全无关,所以我觉得我应该能够为 bicycles
应用程序进行迁移 只有?
我通过将 cars/migrations/__init__.py
重命名为其他名称解决了这个问题,这样 Django 就无法找到它,我可以按预期进行 bicycles
迁移。