Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alembic migrations in "app/migrations" folder cause django development server to fail #145

Open
esquonk opened this issue Jul 15, 2019 · 2 comments

Comments

@esquonk
Copy link

esquonk commented Jul 15, 2019

After setting up a django app and creating a migration using sorcery revision command, I get the following error when starting django dev server:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
    self.check_migrations()
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\loader.py", line 206, in build_graph
    self.load_disk()
  File "C:\Users\mi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\loader.py", line 119, in load_disk
    "Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.exceptions.BadMigrationError: Migration 0001_test in app fares has no Migration class

It appears that the migration check wants all the files in migrations folders in apps to be valid django migrations. For now I work around this by manually adding a dummy django migration to alembic migration file:

from django.db import migrations


class Migration(migrations.Migration):
    dependencies = [
    ]

    operations = [
    ]

One alternative would be using a different folder, perhaps alembic_migrations or revisions to avoid confusion with django ORM migration system.

@shosca
Copy link
Owner

shosca commented Jul 15, 2019

You can disable django migrations using MIGRATION_MODULES, just add a key with app label and with None value
https://docs.djangoproject.com/en/2.2/ref/settings/#migration-modules

@esquonk
Copy link
Author

esquonk commented Jul 15, 2019

Thanks!
I think it would be nice to include this information in the tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants