Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.8 Run a specific migration

In django 1.8 is there a way to run a specific migration and that migration only.

Not for one app only but a specific file in that apps migrations directory.

EDIT TO ORIGINAL:

    Traceback (most recent call last):   File "manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line     utility.execute()   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv     self.execute(*args, **cmd_options)   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute     output = self.handle(*args, **options)   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 146, in handle     plan = executor.migration_plan(targets)   File "/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/db/migrations/executor.py", line 50, in migration_plan     self.loader.graph.node_map[target].children KeyError: ('wagtailcore', '0001_initial') 

Did a little searching and located this https://code.djangoproject.com/ticket/24225#no1

like image 684
bgrantdev Avatar asked Sep 11 '15 20:09

bgrantdev


People also ask

How do I create a custom migration in Django?

Run python manage.py makemigrations to create a migration file. This is an auto-generated migration file using the above command. Now we will add function for transferring data from users table to bank_accounts table.

Which command is used for migration in Django?

migrate executes those SQL commands in the database file. So after executing migrate all the tables of your installed apps are created in your database file. You can confirm this by installing SQLite browser and opening db.

What is the difference between Makemigrations and migrate in Django?

makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.


1 Answers

You can tell Django to move to a specific migration

./manage.py migrate myapp 0005_migration_to_run 

But Django will run every migration up to (or back to) the migration you've chosen.

You could try faking to the migration before

./manage.py migrate --fake myapp 0004_previous_migration ./manage.py migrate myapp 0005_migration_to_run 

You might then want to fake to the migration you started at.

like image 111
Alasdair Avatar answered Nov 16 '22 00:11

Alasdair