32đ
I am removing the old answer as may result in data loss. As ozan mentioned, we can create 2 migrations one in each app. The comments below this post refer to my old answer.
First migration to remove model from 1st app.
$ python manage.py makemigrations old_app --empty
Edit migration file to include these operations.
class Migration(migrations.Migration):
database_operations = [migrations.AlterModelTable('TheModel', 'newapp_themodel')]
state_operations = [migrations.DeleteModel('TheModel')]
operations = [
migrations.SeparateDatabaseAndState(
database_operations=database_operations,
state_operations=state_operations)
]
Second migration which depends on first migration and create the new table in 2nd app. After moving model code to 2nd app
$ python manage.py makemigrations new_app
and edit migration file to something like this.
class Migration(migrations.Migration):
dependencies = [
('old_app', 'above_migration')
]
state_operations = [
migrations.CreateModel(
name='TheModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
],
options={
'db_table': 'newapp_themodel',
},
bases=(models.Model,),
)
]
operations = [
migrations.SeparateDatabaseAndState(state_operations=state_operations)
]
377đ
This can be done fairly easily using migrations.SeparateDatabaseAndState
. Basically, we use a database operation to rename the table concurrently with two state operations to remove the model from one appâs history and create it in anotherâs.
Remove from old app
python manage.py makemigrations old_app --empty
In the migration:
class Migration(migrations.Migration):
dependencies = []
database_operations = [
migrations.AlterModelTable('TheModel', 'newapp_themodel')
]
state_operations = [
migrations.DeleteModel('TheModel')
]
operations = [
migrations.SeparateDatabaseAndState(
database_operations=database_operations,
state_operations=state_operations)
]
Add to new app
First, copy the model to the new appâs model.py, then:
python manage.py makemigrations new_app
This will generate a migration with a naive CreateModel
operation as the sole operation. Wrap that in a SeparateDatabaseAndState
operation such that we donât try to recreate the table. Also include the prior migration as a dependency:
class Migration(migrations.Migration):
dependencies = [
('old_app', 'above_migration')
]
state_operations = [
migrations.CreateModel(
name='TheModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
],
options={
'db_table': 'newapp_themodel',
},
bases=(models.Model,),
)
]
operations = [
migrations.SeparateDatabaseAndState(state_operations=state_operations)
]
- [Django]-How do you configure Django to send mail through Postfix?
- [Django]-(13: Permission denied) while connecting to upstream:[nginx]
- [Django]-How to compare two JSON objects with the same elements in a different order equal?
30đ
I encountered the same problem.
Ozanâs answer helped me a lot but unfortunately was not enough. Indeed I had several ForeignKey linking to the model I wanted to move. After some headache I found the solution so decided to post it to solve people time.
You need 2 more steps:
- Before doing anything, change all your
ForeignKey
linking toTheModel
intoIntegerfield
. Then runpython manage.py makemigrations
- After doing Ozanâs steps, re-convert your foreign keys: put back
ForeignKey(TheModel)
instead ofIntegerField()
. Then make the migrations again (python manage.py makemigrations
). You can then migrate and it should work (python manage.py migrate
)
Hope it helps. Of course test it in local before trying in production to avoid bad suprises đ
- [Django]-How to get the domain name of my site within a Django template?
- [Django]-Annotate with latest related object in Django
- [Django]-Best way to integrate SqlAlchemy into a Django project
16đ
I get nervous hand-coding migrations (as is required by Ozanâs answer) so the following combines Ozanâs and Michaelâs strategies to minimize the amount of hand-coding required:
- Before moving any models, make sure youâre working with a clean baseline by running
makemigrations
. - Move the code for the Model from
app1
toapp2
-
As recommended by @Michael, we point the new model to the old database table using the
db_table
Meta option on the ânewâ model:class Meta: db_table = 'app1_yourmodel'
-
Run
makemigrations
. This will generateCreateModel
inapp2
andDeleteModel
inapp1
. Technically, these migrations refer to the exact same table and would remove (including all data) and re-create the table. -
In reality, we donât want (or need) to do anything to the table. We just need Django to believe that the change has been made. Per @Ozanâs answer, the
state_operations
flag inSeparateDatabaseAndState
does this. So we wrap all of themigrations
entries IN BOTH MIGRATIONS FILES withSeparateDatabaseAndState(state_operations=[...])
. For example,operations = [ ... migrations.DeleteModel( name='YourModel', ), ... ]
becomes
operations = [ migrations.SeparateDatabaseAndState(state_operations=[ ... migrations.DeleteModel( name='YourModel', ), ... ]) ]
-
You also need to make sure the new âvirtualâ
CreateModel
migration depends on any migration that actually created or altered the original table. For example, if your new migrations areapp2.migrations.0004_auto_<date>
(for theCreate
) andapp1.migrations.0007_auto_<date>
(for theDelete
), the simplest thing to do is:- Open
app1.migrations.0007_auto_<date>
and copy itsapp1
dependency (e.g.('app1', '0006...'),
). This is the âimmediately priorâ migration inapp1
and should include dependencies on all of the actual model building logic. - Open
app2.migrations.0004_auto_<date>
and add the dependency you just copied to itsdependencies
list.
- Open
If you have ForeignKey
relationship(s) to the model youâre moving, the above may not work. This happens because:
- Dependencies are not automatically created for the
ForeignKey
changes - We do not want to wrap the
ForeignKey
changes instate_operations
so we need to ensure they are separate from the table operations.
NOTE: Django 2.2 added a warning (models.E028
) that breaks this method. You may be able to work around it with managed=False
but I have not tested it.
The âminimumâ set of operations differ depending on the situation, but the following procedure should work for most/all ForeignKey
migrations:
- COPY the model from
app1
toapp2
, setdb_table
, but DONâT change any FK references. - Run
makemigrations
and wrap allapp2
migration instate_operations
(see above)- As above, add a dependency in the
app2
CreateTable
to the latestapp1
migration
- As above, add a dependency in the
- Point all of the FK references to the new model. If you arenât using string references, move the old model to the bottom of
models.py
(DONâT remove it) so it doesnât compete with the imported class. -
Run
makemigrations
but DONâT wrap anything instate_operations
(the FK changes should actually happen). Add a dependency in all theForeignKey
migrations (i.e.AlterField
) to theCreateTable
migration inapp2
(youâll need this list for the next step so keep track of them). For example:- Find the migration that includes the
CreateModel
e.g.app2.migrations.0002_auto_<date>
and copy the name of that migration. -
Find all migrations that have a ForeignKey to that model (e.g. by searching
app2.YourModel
to find migrations like:class Migration(migrations.Migration): dependencies = [ ('otherapp', '0001_initial'), ] operations = [ migrations.AlterField( model_name='relatedmodel', name='fieldname', field=models.ForeignKey(... to='app2.YourModel'), ), ]
-
Add the
CreateModel
migration as as a dependency:class Migration(migrations.Migration): dependencies = [ ('otherapp', '0001_initial'), ('app2', '0002_auto_<date>'), ]
- Find the migration that includes the
-
Remove the models from
app1
- Run
makemigrations
and wrap theapp1
migration instate_operations
.- Add a dependency to all of the
ForeignKey
migrations (i.e.AlterField
) from the previous step (may include migrations inapp1
andapp2
). - When I built these migrations, the
DeleteTable
already depended on theAlterField
migrations so I didnât need to manually enforce it (i.e.Alter
beforeDelete
).
- Add a dependency to all of the
At this point, Django is good to go. The new model points to the old table and Djangoâs migrations have convinced it that everything has been relocated appropriately. The big caveat (from @Michaelâs answer) is that a new ContentType
is created for the new model. If you link (e.g. by ForeignKey
) to content types, youâll need to create a migration to update the ContentType
table.
I wanted to cleanup after myself (Meta options and table names) so I used the following procedure (from @Michael):
- Remove the
db_table
Meta entry - Run
makemigrations
again to generate the database rename - Edit this last migration and make sure it depends on the
DeleteTable
migration. It doesnât seem like it should be necessary as theDelete
should be purely logical, but Iâve run into errors (e.g.app1_yourmodel
doesnât exist) if I donât.
- [Django]-Django: Get list of model fields?
- [Django]-Django â How to pass several arguments to the url template tag
- [Django]-How can I get the full/absolute URL (with domain) in Django?
15đ
How I did it (tested on Django==1.8, with postgres, so probably also 1.7)
Situation
app1.YourModel
but you want it to go to:
app2.YourModel
- Copy YourModel (the code) from app1 to app2.
-
add this to app2.YourModel:
Class Meta: db_table = 'app1_yourmodel'
-
$ python manage.py makemigrations app2
-
A new migration (e.g. 0009_auto_something.py) is made in app2 with a migrations.CreateModel() statement, move this statement to the initial migration of app2 (e.g. 0001_initial.py) (it will be just like it always have been there). And now remove the created migration = 0009_auto_something.py
-
Just as you act, like app2.YourModel always has been there, now remove the existence of app1.YourModel from your migrations. Meaning: comment out the CreateModel statements, and every adjustment or datamigration you used after that.
-
And of course, every reference to app1.YourModel has to be changed to app2.YourModel through your project. Also, donât forget that all possible foreign keys to app1.YourModel in migrations have to be changed to app2.YourModel
-
Now if you do $ python manage.py migrate, nothing has changed, also when you do $ python manage.py makemigrations, nothing new has been detected.
-
Now the finishing touch: remove the Class Meta from app2.YourModel and do $ python manage.py makemigrations app2 && python manage.py migrate app2 (if you look into this migration youâll see something like this:)
migrations.AlterModelTable( name='yourmodel', table=None, ),
table=None, means it will take the default table-name, which in this case will be app2_yourmodel.
- DONE, with data saved.
P.S during the migration it will see that that content_type app1.yourmodel has been removed and can be deleted. You can say yes to that but only if you donât use it. In case you heavily depend on it to have FKs to that content-type be intact, donât answer yes or no yet, but go into the db that time manually, and remove the contentype app2.yourmodel, and rename the contenttype app1.yourmodel to app2.yourmodel, and then continue by answering no.
- [Django]-Inline in ModelForm
- [Django]-How to test "render to template" functions in django? (TDD)
- [Django]-Django Footer and header on each page with {% extends }
3đ
Another hacky alternative if the data is not big or too complicated, but still important to maintain, is to:
- Get data fixtures using manage.py dumpdata
- Proceed to model changes and migrations properly, without relating the changes
- Global replace the fixtures from the old model and app names to the new
- Load data using manage.py loaddata
- [Django]-Iterating over related objects in Django: loop over query set or use one-liner select_related (or prefetch_related)
- [Django]-Parsing unicode input using python json.loads
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
1đ
You can try the following (untested):
- move the model from
src_app
todest_app
- migrate
dest_app
; make sure the schema migration depends on the latestsrc_app
migration (https://docs.djangoproject.com/en/dev/topics/migrations/#migration-files) - add a data migration to
dest_app
, that copies all data fromsrc_app
- migrate
src_app
; make sure the schema migration depends on the latest (data) migration ofdest_app
â that is: the migration of step 3
Note that you will be copying the whole table, instead of moving it, but that way both apps donât have to touch a table that belongs to the other app, which I think is more important.
- [Django]-Using Cloudfront with Django S3Boto
- [Django]-Django/DRF â 405 Method not allowed on DELETE operation
- [Django]-Are there any plans to officially support Django with IIS?
1đ
Copied from my answer at https://stackoverflow.com/a/47392970/8971048
In case you need to move the model and you donât have access to the app anymore (or you donât want the access), you can create a new Operation and consider to create a new model only if the migrated model does not exist.
In this example I am passing âMyModelâ from old_app to myapp.
class MigrateOrCreateTable(migrations.CreateModel):
def __init__(self, source_table, dst_table, *args, **kwargs):
super(MigrateOrCreateTable, self).__init__(*args, **kwargs)
self.source_table = source_table
self.dst_table = dst_table
def database_forwards(self, app_label, schema_editor, from_state, to_state):
table_exists = self.source_table in schema_editor.connection.introspection.table_names()
if table_exists:
with schema_editor.connection.cursor() as cursor:
cursor.execute("RENAME TABLE {} TO {};".format(self.source_table, self.dst_table))
else:
return super(MigrateOrCreateTable, self).database_forwards(app_label, schema_editor, from_state, to_state)
class Migration(migrations.Migration):
dependencies = [
('myapp', '0002_some_migration'),
]
operations = [
MigrateOrCreateTable(
source_table='old_app_mymodel',
dst_table='myapp_mymodel',
name='MyModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=18))
],
),
]
- [Django]-Where to put business logic in django
- [Django]-How to express a One-To-Many relationship in Django?
- [Django]-In Django, how does one filter a QuerySet with dynamic field lookups?
0đ
This is tested roughly, so do not forget to backup your DB!!!
For example, there are two apps: src_app
and dst_app
, we want to move model MoveMe
from src_app
to dst_app
.
Create empty migrations for both apps:
python manage.py makemigrations --empty src_app
python manage.py makemigrations --empty dst_app
Letâs assume, that new migrations are XXX1_src_app_new
and XXX1_dst_app_new
, previuos top migrations are XXX0_src_app_old
and XXX0_dst_app_old
.
Add an operation that renames table for MoveMe
model and renames its app_label in ProjectState to XXX1_dst_app_new
. Do not forget to add dependency on XXX0_src_app_old
migration. The resulting XXX1_dst_app_new
migration is:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
# this operations is almost the same as RenameModel
# https://github.com/django/django/blob/1.7/django/db/migrations/operations/models.py#L104
class MoveModelFromOtherApp(migrations.operations.base.Operation):
def __init__(self, name, old_app_label):
self.name = name
self.old_app_label = old_app_label
def state_forwards(self, app_label, state):
# Get all of the related objects we need to repoint
apps = state.render(skip_cache=True)
model = apps.get_model(self.old_app_label, self.name)
related_objects = model._meta.get_all_related_objects()
related_m2m_objects = model._meta.get_all_related_many_to_many_objects()
# Rename the model
state.models[app_label, self.name.lower()] = state.models.pop(
(self.old_app_label, self.name.lower())
)
state.models[app_label, self.name.lower()].app_label = app_label
for model_state in state.models.values():
try:
i = model_state.bases.index("%s.%s" % (self.old_app_label, self.name.lower()))
model_state.bases = model_state.bases[:i] + ("%s.%s" % (app_label, self.name.lower()),) + model_state.bases[i+1:]
except ValueError:
pass
# Repoint the FKs and M2Ms pointing to us
for related_object in (related_objects + related_m2m_objects):
# Use the new related key for self referential related objects.
if related_object.model == model:
related_key = (app_label, self.name.lower())
else:
related_key = (
related_object.model._meta.app_label,
related_object.model._meta.object_name.lower(),
)
new_fields = []
for name, field in state.models[related_key].fields:
if name == related_object.field.name:
field = field.clone()
field.rel.to = "%s.%s" % (app_label, self.name)
new_fields.append((name, field))
state.models[related_key].fields = new_fields
def database_forwards(self, app_label, schema_editor, from_state, to_state):
old_apps = from_state.render()
new_apps = to_state.render()
old_model = old_apps.get_model(self.old_app_label, self.name)
new_model = new_apps.get_model(app_label, self.name)
if self.allowed_to_migrate(schema_editor.connection.alias, new_model):
# Move the main table
schema_editor.alter_db_table(
new_model,
old_model._meta.db_table,
new_model._meta.db_table,
)
# Alter the fields pointing to us
related_objects = old_model._meta.get_all_related_objects()
related_m2m_objects = old_model._meta.get_all_related_many_to_many_objects()
for related_object in (related_objects + related_m2m_objects):
if related_object.model == old_model:
model = new_model
related_key = (app_label, self.name.lower())
else:
model = related_object.model
related_key = (
related_object.model._meta.app_label,
related_object.model._meta.object_name.lower(),
)
to_field = new_apps.get_model(
*related_key
)._meta.get_field_by_name(related_object.field.name)[0]
schema_editor.alter_field(
model,
related_object.field,
to_field,
)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
self.old_app_label, app_label = app_label, self.old_app_label
self.database_forwards(app_label, schema_editor, from_state, to_state)
app_label, self.old_app_label = self.old_app_label, app_label
def describe(self):
return "Move %s from %s" % (self.name, self.old_app_label)
class Migration(migrations.Migration):
dependencies = [
('dst_app', 'XXX0_dst_app_old'),
('src_app', 'XXX0_src_app_old'),
]
operations = [
MoveModelFromOtherApp('MoveMe', 'src_app'),
]
Add dependency on XXX1_dst_app_new
to XXX1_src_app_new
. XXX1_src_app_new
is no-op migration that is needed to make sure that future src_app
migrations will be executed after XXX1_dst_app_new
.
Move MoveMe
from src_app/models.py
to dst_app/models.py
. Then run:
python manage.py migrate
Thatâs all!
- [Django]-How to get Request.User in Django-Rest-Framework serializer?
- [Django]-Best practices for getting the most testing coverage with Django/Python?
- [Django]-Django model one foreign key to many tables
0đ
Lets say you are moving model TheModel from app_a to app_b.
An alternate solution is to alter the existing migrations by hand. The idea is that each time you see an operation altering TheModel in app_aâs migrations, you copy that operation to the end of app_bâs initial migration. And each time you see a reference âapp_a.TheModelâ in app_aâs migrations, you change it to âapp_b.TheModelâ.
I just did this for an existing project, where I wanted to extract a certain model to an reusable app. The procedure went smoothly. I guess things would be much harder if there were references from app_b to app_a. Also, I had a manually defined Meta.db_table for my model which might have helped.
Notably you will end up with altered migration history. This doesnât matter, even if you have a database with the original migrations applied. If both the original and the rewritten migrations end up with the same database schema, then such rewrite should be OK.
- [Django]-Get count of related model efficiently in Django
- [Django]-How to change the name of a Django app?
- [Django]-How to merge consecutive database migrations in django 1.9+?
0đ
- change the names of old models to âmodel_name_oldâ
- makemigrations
- make new models named âmodel_name_newâ with identical relationships on the related models
(eg. user model now has user.blog_old and user.blog_new) - makemigrations
- write a custom migration that migrates all the data to the new model tables
- test the hell out of these migrations by comparing backups with new db copies before and after running the migrations
- when all is satisfactory, delete the old models
- makemigrations
- change the new models to the correct name âmodel_name_newâ -> âmodel_nameâ
- test the whole slew of migrations on a staging server
- take your production site down for a few minutes in order to run all migrations without users interfering
Do this individually for each model that needs to be moved.
I wouldnât suggest doing what the other answer says by changing to integers and back to foreign keys
There is a chance that new foreign keys will be different and rows may have different IDs after the migrations and I didnât want to run any risk of mismatching ids when switching back to foreign keys.
- [Django]-Django-Forms with json fields
- [Django]-How do I create a slug in Django?
- [Django]-Django custom field validator vs. clean
0đ
Introduction
I had to move the model from one app to another.
Tried various methods, such as:
- adding class Meta: db_table = âapp1_yourmodelâ,
- migrations.SeparateDatabaseAndState,
- renaming the table name by hand,
- copying the data during the migration process by running raw sql queries with RunSQL,
- etc
But after each case I would face some kind of error would occur.
I will describe a method that I have used and that has worked for me just fine.
It was very good to practice this in my DEV environment, having copies of sqlite3 DB files and to be able to visually see the content of the DB as I was doing this.
But for those that do not have access to sqlite3 DB file or can not preview their content in the GUI as I could in VScode or in sqlitebrowser, I will write as detailed instructions as I can below. They helped me to execute the same commands in my PROD server afterwards(did not have a gui as well).
note: you can ignore the --settings=settings.development
everywhere you see it, you will not need it.
If you see a command like such:
python manage.py makemigrations base_app --settings=settings.development
It means that you have to run your command like that:
python manage.py makemigrations base_app
And change the "base_app" to your app name.
My preferred method
So what I will do is this:
- Move the models.py file to a new app
- "makemigrations" for new app only
- "migrate" the changes for the new app only
- Prepare for data copying
- Run some raw sql commands to copy the data to the new app
- "makemigrations" of the old app to delete the old tables
- Final check
Move the models.py file to a new app
my old app = base_app
my new app = website_fixes_app
Move the models.py file from the old app to the new app. Old app should not have any models.py file left.
"makemigrations" for new app only
Make sure you have a copy of your current db!
makemigrations FOR THE NEW APP only, it will create the migrations file for new model file. You can see that I specify the new app name in the makemigrations command below, so the makemigrations would not happen globally, but only for the chosen app.
python manage.py makemigrations website_fixes_app --settings=settings.development
"migrate" the changes for the new app only
The new tables will be created. Notice I only again specify the new app name.
python manage.py migrate website_fixes_app --settings=settings.development
Now you have two sets of tables. Old tables and new tables. Rows are the same in both tables.
Now the fun part. Copy the data from one to another!
Prepare for data copying
Since I use sqlite3 db I need a "driver" of some sort to connect to the DB and run queries. If you are using a different DB â you might have to use a different driver. SQL commands should be similar as well.
note: or do it in db viewer for sqlite app if you can. Itâs better to SEE the actual changes and content in the db.
sudo apt install sqlite3
sqlite3 your_db_filename.sqlite3
Confirm that the tables were created by the migration.
# open the db
sqlite3 your_db_filename.sqlite3
Print out the table names, notice that the old tables as well as the new tables exist.
.tables
SELECT * FROM old_table_name;
Run some raw sql commands to copy the data to the new app
Open the db once again if you have exited it before.
sqlite3 your_db_filename.sqlite3
Run these SQL commands. Adjust the fields and table names to your table names.
An example:
INSERT INTO your_new_table_name (id, title)
SELECT id, title
FROM your_old_table_name;
# then to check:
SELECT * FROM your_new_table_name;
In my case I had to run these 3 queries:
INSERT INTO website_fixes_app_websitefix (id, title, description, date_created, status)
SELECT id, title, description, date_created, status
FROM base_app_websitefix;
# check:
SELECT * FROM website_fixes_app_websitefix;
INSERT INTO website_fixes_app_websitefix_tags (id, websitefix_id, websitefixtag_id)
SELECT id, websitefix_id, websitefixtag_id
FROM base_app_websitefix_tags;
check:
SELECT * FROM website_fixes_app_websitefix_tags;
INSERT INTO website_fixes_app_websitefixtag (id, name)
SELECT id, name
FROM base_app_websitefixtag;
check:
SELECT * FROM website_fixes_app_websitefixtag;
exit the sqlite3 with CTRL + D
.
"makemigrations" of the old app to delete the old tables
If your new tables contain the data of the old tables, we can remove the old tables (good that you have a copy of your db, so no worries here, we can always go back.).
Make migrations of the old app to remove the old tables from the db.
You can see that I am now not making global migrations again, I am just focusing on one app â my old app (base_app).
python manage.py makemigrations base_app --settings=settings.development
python manage.py migrate base_app --settings=settings.development
Final check
check if the old tables were removed:
sqlite3 your_db_filename.sqlite3
.tables
SELECT * FROM old_table_name;
Start your server and see if the app runs fine. If you have adjusted your app to read from the new tables â then it should work flawlesly.
We can now delete the migrations folder from the old app.
Now whenever you will have to modify the models in the new app â you can do so with no problems. No errors will occur.
- [Django]-DRF: custom ordering on related serializers
- [Django]-Can't compare naive and aware datetime.now() <= challenge.datetime_end
- [Django]-What is related_name used for?
0đ
In case you do not have custom migrations, one could just recreate everything. Remove everything, migrate everything freshly. (DO IT ON YOUR OWN RISK)
Preparations:
- Ensure all models have:
class Meta:
db_table = 'just_model_name' # without app_name prefix
- VERY IMPORTANT to make sure that all your previous-current migrations are created and applied to all your servers / test-servers, team mates, etc. Pay time here.
- Move everything you want.
- Reload django and check that nothing is mixed up and it still stars normally.
Job:
- Remove all migration files, so there stands empty
migrations/
folders with only__init__.py
files. - Remove all migration history. Just clear
django_migrations
table or:
from django.db.migrations.recorder import MigrationRecorder
MigrationRecorder.Migration.objects.all().delete()
python manage.py makemigrations
again.python manage.py migrate --fake
.
Probably youâll get some errors here, like "previous dependency migrationsâŠ, could not be applied⊠because of an app, bla-bla-bla".
And that errors will guide you, so, probably youâll have to migrate by app:
python manage.py migrate myapp1 --fake
python manage.py migrate --fake # will give another guiding error
python manage.py migrate myapp2 --fake
I do not say itâs best or even good solution.
But I am happy with it.
Surely it preserves data.
- [Django]-Django migration fails with "__fake__.DoesNotExist: Permission matching query does not exist."
- [Django]-Django: How to format a DateField's date representation?
- [Django]-Create empty queryset by default in django form fields