Is there any way to properly create data-migrations for third party Django apps?
Running python manage.py makemigrations --empty <externa-app-label>
works, but creates the migrations in the app's directory (which is inside the virtual environment... don't want to mess with that).
Here's my case:
I need to replace one of the internal apps of a Django project with an external app with similar functionality, and then remove the old internal app. These apps have models, and there is an existing database for the project which will need to be migrated. I would associate the data-migration with the old app if I weren't going to be deleting it later.
A simpler example of the need for something like this might be just needing to fill a third-party app with some initial data.
Just create the data migration as part of one of your other internal apps, and just do the data manipulation there (maybe even create a temporary app just for that purpose?)
The important bit is to add a new dependency in the data migration file. Something like this, but of course look up the latest migration name in the extenralapp/migrations
directory (or some other directory if overridden in settings.MIGRATION_MODULES
).
class Migration(migrations.Migration):
dependencies = [
('yourapp', '0004_auto_20151216_1509'),
('externalapp', '0011_20010203_1415'), # this line
]
...
A related thing...
If using ContentType
and / or auth.Permission
models, you might run into problems trying to fetch them. Both those models are created at the end of a successful manage.py migrate
command.
In this case it might very well happen that your migration will run fine on its own, but fail if you run all the migrations in one go (i.e. on a clean db). For more info and a workaround, see #23422 Cannot add Permission to Group in data migration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With