Let's imagine that you have 2 django apps:
So first one has model
Article as you already guessed.
So we need to move our
Article model from
article app to
- Copy your code of
- We need to specify database table for our moved model. At our example it is
article_article. You need to add to your
blog.Articlemodel next lines:
class Meta: db_table = 'article_article'
Now you can
python manage.py makemigrations blogfor getting django migration for creating model or you could get creation migration from your
articleapp and place it to migrated migration in
blogapp. If you run above command, you need to delete this migration after place it into previously migrated migration.
Now you need to change all references in your whole project to new new reference of your model. It can be ForeignKey, import etc.
Verify that you do all correctly with command:
./manage.py migrate. Nothing should be migrated. If not - verify previous steps, because we just changed place of your model code, not database table name.
Last step will be remove
class Metaand run next command:
./manage.py makemigrations blog ./manage.py migrate blog
After create migration you could see something next operation at migration:
operations = [ migrations.AlterModelTable( name='blog', table=None, ), ]
table=None means it will take the default table-name, which in this case will be
This solution was tested with Django 1.11 and Postgres database with ForeignKey relation.
Hope it helps.