InvalidBasesError: Cannot resolve bases for []

后端 未结 14 949
遥遥无期
遥遥无期 2021-02-03 23:03

When I run tests I get this error during database initialization:

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [

        
相关标签:
14条回答
  • 2021-02-03 23:25

    add a folder named "migrations" and in this folder create "__init__.py" file

    0 讨论(0)
  • 2021-02-03 23:25

    If this is only happening when running python manage.py test (maybe because you have already made the necessary migrations), you should explicitly say that contrib.auth should not migrate in the MIGRATION_MODULES of your settings module.

    MIGRATION_MODULES(
            'auth': "contrib.auth.migrations_not_used_in_tests",
    )
    
    0 讨论(0)
  • 2021-02-03 23:28

    happened to me with no other app - just because I renamed a model which was a base for other models (and maybe created that sub-models within the same migration) renaming the super-model to it's original name solved it for me

    0 讨论(0)
  • 2021-02-03 23:30

    Simply creating a migrations directory at the root of your app (so users/migrations/ in your case) and adding an empty __init__.py file might resolve your issue. At least it did for me when I was getting the same error.

    But you're better off running makemigrations for your app, as suggested by @zenofewords above. That will create the directory for you AND generate migrations for your proxy models.

    Why does Django create migration files for proxy models?

    Your tests are looking for those migrations and aren't finding them.

    0 讨论(0)
  • 2021-02-03 23:32

    I had this problem after I renamed the parent table of a bunch of my proxy models. I resolved it by:

    1. Deleting the migration file that had the name change for the parent table.
    2. Using the postgres terminal, I renamed the parent table to its previous name.
    3. Ran makemigrations and migrate again
    0 讨论(0)
  • 2021-02-03 23:33

    After a lot of digging on this the only thing that worked for me was

    comment out the offending apps, run migrations, then add them in again.

    Just a workaround but hopefully it helps somebody.

    0 讨论(0)
提交回复
热议问题