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
Related
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.
I'm new to South and I'm trying to perform a migration. It worked fine in local, but when I pushed the code to Heroku and tried to migrate I got this error:
Traceback (most recent call last):
File "manage.py", line 57, in <module>
execute_from_command_line()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/__init__.py", line 200, in migrate_app
applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/__init__.py", line 81, in check_migration_histories
m = h.get_migration()
File "/app/.heroku/python/lib/python2.7/site-packages/south/models.py", line 34, in get_migration
return self.get_migrations().migration(self.migration)
File "/app/.heroku/python/lib/python2.7/site-packages/south/models.py", line 31, in get_migrations
return Migrations(self.app_name)
File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/base.py", line 64, in __call__
self.instances[app_label] = super(MigrationsMetaclass, self).__call__(app_label_to_app_module(app_label), **kwds)
File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/base.py", line 90, in __init__
self.set_application(application, force_creation, verbose_creation)
File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/base.py", line 162, in set_application
raise exceptions.NoMigrations(application)
south.exceptions.NoMigrations: Application '<module 'django_extensions' from '/app/.heroku/python/lib/python2.7/site-packages/django_extensions/__init__.pyc'>' has no migrations.
In local I did:
python manage.py schemamigration spicemodels --auto
python manage.py migrate spicemodels
Then I pushed the migration files to Heroku and accessed the app using:
heroku run bash --app <app-name>
I then went into the correct directory and ran:
python manage.py migrate spicemodels
That is when I got the error above.
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.
I am trying to deploy my Django-cms site on Heroku, and I'm really struggling with migrations. I'm running django 1.7.7 and django-cms 3.1.0. I don't have any data to migrate, so I just want to create the empty tables.
With a fresh Heroku Postgres database:
heroku run python manage.py migrate contenttypes
output:
Operations to perform:
Apply all migrations: contenttypes
Running migrations:
Applying contenttypes.0001_initial...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 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
if self.detect_soft_applied(migration):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
apps = project_state.render()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/state.py", line 75, in render
"for more" % new_unrendered_models
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'djangocms_link.Link'>, <ModelState: 'djangocms_text_ckeditor.Text'>, <ModelState: 'djangocms_file.File'>, <ModelState: 'djangocms_inherit.InheritPagePlaceholder'>, <ModelState: 'djangocms_column.MultiColumns'>, <ModelState: 'djangocms_column.Column'>, <ModelState: 'djangocms_googlemap.GoogleMap'>, <ModelState: 'djangocms_flash.Flash'>, <ModelState: 'djangocms_snippet.SnippetPtr'>, <ModelState: 'djangocms_video.Video'>, <ModelState: 'djangocms_teaser.Teaser'>, <ModelState: 'djangocms_picture.Picture'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
What I don't understand is that contenttypes doesn't depend on any of those models in the djangocms plugins. If I try to migrate any of the plugins first, I get a stack trace and this:
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
UPDATE: Following the documentation for the various django-cms plugins, I added MIGRATION_MODULES to settings.py. Now when I run:
heroku run python manage.py makemigrations djangocms_text_ckeditor
a migration is created:
Migrations for 'djangocms_text_ckeditor':
0001_initial.py:
- Create model Text
Sounds great! But...
heroku run python manage.py migrate djangocms_text_ckeditor
output:
Operations to perform:
Apply all migrations: (none)
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 44, in get_for_model
ct = self._get_from_cache(opts)
File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 34, in _get_from_cache
return self.__class__._cache[self.db][key]
KeyError: 'default'
During handling of the above exception, another exception occurred:
[long stack trace ommitted]
As stated in djangocms_link module documentation - https://github.com/divio/djangocms-link
If using Django 1.7 add 'djangocms_link': 'djangocms_link.migrations_django', to MIGRATION_MODULES
And same for djangocms_file module
So basically you should have in your settings.py
MIGRATION_MODULES = {
'djangocms_link': 'djangocms_link.migrations_django',
'djangocms_file': 'djangocms_file.migrations_django'
}
I am trying to add south to my project on Heroku. I followed the following steps.
heroku run easy_install South
Added 'south' in INSTALLED_APPS in settings.py
Then
heroku run ./manage.py syncdb
heroku run ./manage.py convert_to_south sheets
Traceback
Running `./manage.py convert_to_south sheets` attached to terminal... up, run.2005
Creating migrations directory at '/app/sheets/migrations'...
Creating __init__.py in '/app/sheets/migrations'...
+ Added model sheets.Sheets
+ Added model sheets.UserSheets
+ Added M2M table for users on sheets.UserSheets
+ Added model sheets.SheetScribble
+ Added model sheets.SheetScribbleComment
+ Added model sheets.Tasks
+ Added model sheets.TaskComment
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate sheets
- Soft matched migration 0001 to 0001_initial.
Running migrations for sheets:
- Nothing to migrate.
- Loading initial data for sheets.
Installed 0 object(s) from 0 fixture(s)
App 'sheets' converted. Note that South assumed the application's models matched the database
(i.e. you haven't changed it since last syncdb); if you have, you should delete the sheets/migrations
directory, revert models.py so it matches the database, and try again.
then when I try to convert my second app to south,
heroku run ./manage.py convert_to_south scribbler
I get this error
Running `./manage.py convert_to_south scribbler` attached to terminal... up, run.6046
Creating migrations directory at '/app/scribbler/migrations'...
Creating __init__.py in '/app/scribbler/migrations'...
+ Added model scribbler.ScribbleMedia
+ Added model scribbler.Scribble
+ Added model scribbler.Tag
+ Added M2M table for scribbles on scribbler.Tag
+ Added model scribbler.SharedScribble
+ Added M2M table for users_favored on scribbler.SharedScribble
+ Added model scribbler.ScribbleComment
+ Added model scribbler.Connections
+ Added unique constraint for ['following', 'followers'] on scribbler.Connections
+ Added model scribbler.UserProfile
+ Added model scribbler.Invitation
+ Added model scribbler.Notifications
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate scribbler
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/convert_to_south.py", line 87, in handle
delete_ghosts=options.get("delete_ghosts", False),
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/__init__.py", line 193, in migrate_app
applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/__init__.py", line 74, in check_migration_histories
m = h.get_migration()
File "/app/.heroku/venv/lib/python2.7/site-packages/south/models.py", line 34, in get_migration
return self.get_migrations().migration(self.migration)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/models.py", line 31, in get_migrations
return Migrations(self.app_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 61, in __call__
self.instances[app_label] = super(MigrationsMetaclass, self).__call__(app_label_to_app_module(app_label), **kwds)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 89, in __init__
self.set_application(application, force_creation, verbose_creation)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/migration/base.py", line 161, in set_application
raise exceptions.NoMigrations(application)
south.exceptions.NoMigrations: Application '<module 'sheets' from '/app/sheets/__init__.py'>' has no migrations.
I am not sure what the problem is.
You shouldn't be running those commands ON heroku. You should be doing that on your local environment, pushing them to heroku, then running the migrate commands.
It has an "ephemeral filesystem" which probably cleared between those two commands. So south has a record of a 0001 migration, but it doesn't exist.
I'm not sure why it's being thrown during the "convert_to_south" command (some new south feature?), but that's my best guess.
Try doing it locally, committing the migration files, then proceeding to run the migrate commands on heroku.