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
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.
Related
I'm trying to deploy my app on PythonAnywhere and when i go to apply the migrations i get an error that a migration dependency does not exist.
I've completely reset the migrations by deleting them from the migrations folder, dropping the database and re-creating it, and running makemigrations.
I only have my one initial migration now and everything works on my local machine.
workflow goes like this:
1 - clone the current version I'm using to PythonAnywhere.
2 - run ./manage migrate to initialize the database (the very first time) and get error:
(rwe) 17:00 ~/rwe (develop)$ ./manage.py migrate
asyncio DEBUG Using selector: EpollSelector
Traceback (most recent call last):
File "./manage.py", line 21, in <module>
main()
File "./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 274, in build_graph
raise exc
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 248, in build_graph
self.graph.validate_consistency()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/graph.py", line 195, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/graph.py", line 195, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/graph.py", line 58, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration backend.0001_initial dependencies reference nonexistent parent node ('auth', '0013_delete_users')
(rwe) 17:12 ~/rwe (develop)$
The website loads, and I can browse, etc.. I just can't use anything that relies on the database considering the initial migration hasn't been applied.
The only real change between the systems is the secret key is different for production and DEBUG=False
I figured it out.
I updated django from 2.2.3 to 3.0.3 and the migrations I am missing must have generated during my use of 2.2.3.
worked for me but not for my PythonAnywhere server. I've recreated my virtualenv on my dev machine and reset all my migrations. Everything is now matching up without issue.
When I try to run migration I get "Migration urls in app *** has no Migration class"? I just added new app.
Have no idea what direction to look. Traceback:
C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\models\__init__.py:55:
RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated
in favor of the new application loading system.
from . import loading
Traceback (most recent call last): File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "...\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "...\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "...\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "...\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "...\django\core\management\commands\makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "...\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "...\django\db\migrations\loader.py", line 174, in build_graph
self.load_disk()
File "...\django\db\migrations\loader.py", line 109, in load_disk
"Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.loader.BadMigrationError: Migration urls in app expense has no
Migration class
That exception
BadMigrationError: "Migration *** in app *** has no Migration class"
is raised if the "migrations/" directory of the application contains a file that is not a valid migration file.
In your case it is a file "urls.py" in migrations of the application "expense".
I wanted to validate if there is a bug in makemigrations in django 1.8 with sql lite or I am doing something wrong.
After I Dropped my DB and deleted all migration folders. I run
python manage.py makemigrations
python manage.py migrate
DB gets created no problems.
2.I have to modify existing model in one of the apps (app abc)
I perform my change and run again
python manage.py makemigrations
3.it doesn't find any changes
then I run same thing again but with app name
python manage.py makemigrations abc
4.It does some updates in migrations , I believe it recreates all the tables and not just my change !!!!
5.Then I execute
python manage.py migrate
and getting error that table already exists .
Is it a bug in django framework or I am doing something wrong and there is a reason why it behaves this way?
Copy paste from my shell starting from step 2:
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py makemigrations
No changes detected
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py makemigrations purchase
Migrations for 'purchase':
0001_initial.py:
- Create model PO
- Create model POmaterial
(mrp) C:\Users\I812624\dev\mrp\src>python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: customer, manufacture, product, django_filters, a
utofixture, staticfiles, messages, smart_selects, watson, sales, item, django_co
untries, mptt, inventory, django_select2, production, main, crispy_forms
Apply all migrations: purchase, vendor, sessions, admin, sites, flatpages, con
tenttypes, auth, registration
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying purchase.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 441, in execute
output = self.handle(*args, **options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\executor
.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=f
ake_initial)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\executor
.py", line 147, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\migratio
n.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\migrations\operatio
ns\models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\base\schem
a.py", line 282, in create_model
self.execute(sql, params or None)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\base\schem
a.py", line 107, in execute
cursor.execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\utils.py", line 97,
in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\sqlite3\ba
se.py", line 316, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: table "purchase_po" already exists
To answer my own question .
So what I have figured out . I believe the problem is that I have originally deleted the folders migrations and when I run makemigrations without specifying particular app it does create a DB but it dosent create the folder makemigrations with ____init____.py inside it.
solution each time when you drop db and delete migrations folder for whatever reason dont just delete the migrations folder but only its content excluding init file.
Or when you do delete the folder run make migrations individually for each app as #MicroPyramid suggested.
Without doing deeper investigation it looks to me or as confusing designed behaviour or a bug from Django side.
Django verstion 1.8
Trying to migrate a newly added app in my project. Here is the traceback error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 318, in build_graph
_reraise_missing_dependency(migration, parent, e)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 288, in _reraise_missing_dependency
raise exc
django.db.migrations.graph.NodeNotFoundError: Migration weather.0001_initial dependencies reference nonexistent parent node (u'machines', u'0006_auto_20150921_1327')
I have not found much helpful information in researching this. Syntax is correct in all models. Here is what doesn't make sense: this is just a copy of a working project. So it works on one computer, but not here. The machines model it's referencing has already been created and is working. Any ideas???
You are getting the error because the migration you are trying to run, weather.0001_initial, depends on a migration machines.0006_auto_20150921_1327 which does not exist.
If you can't find the missing migration file, you'll have to delete and recreate the migrations for the weather app, so that they don't depend on the missing migration.
You are getting this error because you are missing the
__init__.py
file in your migrations folder.
For me, it worked after adding this file.
I'm trying to deploy a Django (1.8) app to Heroku, runtime Python 3.4.2. The app runs succesfully (except the fact that tables are not created), but when trying run the syncdb I get the following error:
Running `python manage.py syncdb` attached to terminal... up, run.5851
/app/.heroku/python/lib/python3.4/site-packages/django/core/management
/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command
will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 157, in check_key
return list(self.graph.root_nodes(key[0]))[0]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django /core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 287, in build_graph
parent = self.check_key(parent, key[0])
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 164, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: authentication
I'm using sqlite.
On your dev machine, create your migrations with python manage.py makemigrations. Then, assuming your migrations folders are pushed to heroku, on heroku run python manage.py migrate instead of python manage.py syncdb. See the docs.
I hade to enter the heroku's machine bash :
heroku run bash
and then make the makemigrations:
heroku run python manage.py makemigrations
Finally,
heroku run python manage.py migrate
For me i solved this issue by using same command what we use in our local server with prefix "heroku run" that's it..
for eg:-
python manage.py makemigrations
it will work in our local but for heroku, like this :-
heroku run python manage.py makemigrations