30👍
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.
33👍
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.
- [Django]-Django, ReactJS, Webpack hot reload
- [Django]-Django REST framework post array of objects
- [Django]-How to add column in ManyToMany Table (Django)
23👍
I’ve come across this issue, and as commenting out the model isn’t really a solution, I’ve found that setting the undocumented auto_created = True
to the Meta class will make Django ignore it.
class GroupProxy(Group):
class Meta:
proxy = True
auto_created = True
- [Django]-Django: how to do calculation inside the template html page?
- [Django]-Django DoesNotExist
- [Django]-How to save a model without sending a signal?
15👍
Have you tried running manage.py makemigrations <app_label>
on your app before running tests?
Also, check if the app which model(s) you are trying to Proxy is included in your INSTALLED_APPS.
- [Django]-How to get primary keys of objects created using django bulk_create
- [Django]-Django template can't loop defaultdict
- [Django]-How can I embed django csrf token straight into HTML?
7👍
add a folder named "migrations
" and in this folder create "__init__.py
" file
- [Django]-No Module named django.core
- [Django]-Duplicating model instances and their related objects in Django / Algorithm for recusrively duplicating an object
- [Django]-How to work around lack of support for foreign keys across databases in Django
6👍
Having spent the majority of this afternoon trying to solve this error myself, going through every conceivable mixture of ‘commenting out apps’, ‘dropping tables’ and dropping entire databases I found that my issue was caused by a simple lack of a ‘migrations’ folder and an __ init__.py file inside of said folder.
One of the older answers which was correct is now no longer correct as they have fixed the issue mentioned here.
Check every directory that contains the model mentioned in ‘init.py’ and it should go away.
Probably won’t solve everyone’s case but it helped mine.
- [Django]-What is choice_set in this Django app tutorial?
- [Django]-How to create a Django FloatField with maximum and minimum limits?
- [Django]-Django storages aws s3 delete file from model record
5👍
I also faced this issue (after doing some complex model inheritance). One of my migrations contained
migrations.CreateModel(
name='Offer',
fields=[
# ...
],
options={
# ...
},
bases=('shop.entity',),
),
I deleted shop.Entity
model entirely, but the migration was referencing it in bases
attribute. So I just deleted bases=('shop.entity',)
and it works. It will probably break an opportunity to migrate from the beginning, but at least allows to migrate further on.
Another advice would be: go directly to django code and inspect what’s causing “bases” trouble. Go to django/db/migrations/state.py
and add a breakpoint:
try:
bases = tuple(
(apps.get_model(base) if isinstance(base, six.string_types) else base)
for base in self.bases
)
except LookupError:
print(self.bases) # <-- print the bases
import ipdb; ipdb.set_trace() # <-- debug here
raise InvalidBasesError("Cannot resolve one or more bases from %r" % (self.bases,))
- [Django]-Django AutoField with primary_key vs default pk
- [Django]-Circular dependency in Django Rest Framework serializers
- [Django]-MySQL ERROR 2026 – SSL connection error – Ubuntu 20.04
3👍
I had this problem after I renamed the parent table of a bunch of my proxy models. I resolved it by:
- Deleting the migration file that had the name change for the parent table.
- Using the postgres terminal, I renamed the parent table to its previous name.
- Ran
makemigrations
andmigrate
again
- [Django]-Why use Django on Google App Engine?
- [Django]-Django migrations RunPython not able to call model methods
- [Django]-Django templates – split string to array
0👍
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",
)
- [Django]-Annotate a sum of two fields multiplied
- [Django]-How to set django model field by name?
- [Django]-Is there a datetime ± infinity?
0👍
One possibility is that the deleting or creating of a model in the migration file is in the wrong order. I experienced this in Django 1.7.8 when the base model was BEFORE the derived model. Swapping the order for deleting the model fixed the issue.
- [Django]-Can the Django ORM store an unsigned 64-bit integer (aka ulong64 or uint64) in a reliably backend-agnostic manner?
- [Django]-Django default_from_email name
- [Django]-Steps to Troubleshoot "django.db.utils.ProgrammingError: permission denied for relation django_migrations"
0👍
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
- [Django]-Is there a datetime ± infinity?
- [Django]-How to redirect with messages to display them in Django Templates?
- [Django]-Get current user in Model Serializer
0👍
I faced the same issue and adding app_label
attribute in class Meta:
solved the error :
class GroupProxy(Group):
class Meta:
proxy = True
app_label = '<app in which you want this model>'
verbose_name = Group._meta.verbose_name
verbose_name_plural = Group._meta.verbose_name_plural
- [Django]-Django: How to format a DateField's date representation?
- [Django]-Django Rest Framework POST Update if existing or create
- [Django]-How to use less css with django?
0👍
If this occurs to you in an app that already has a migrations folder (and a init.py file in it), delete all other files, and run makemigrations
and migrate
again.
P.S.: You may need to reconfigure your models.py or some tables in your database manually.
- [Django]-Can I make STATICFILES_DIR same as STATIC_ROOT in Django 1.3?
- [Django]-How to tell if a task has already been queued in django-celery?
- [Django]-Django Server Error: port is already in use
0👍
Just incase anyone made the same mistake as me, I had the same issue because I hadn’t made any migrations for the Proxy models. It didn’t seem necessary to me as they don’t have their own DB tables and I didn’t see anything mentioning this in the docs. python manage.py makemigrations <APP_NAME>
fixed it right up.
- [Django]-Assign variables to child template in {% include %} tag Django
- [Django]-How to add a new field to a model with new Django migrations?
- [Django]-Django models | get specific columns
0👍
There’s a related question. See my answer here https://stackoverflow.com/a/67500550/502045
TL;DR
Create your own operation to remove bases
class RemoveModelBasesOptions(ModelOptionOperation):
def __init__(self, name):
super().__init__(name)
def deconstruct(self):
kwargs = {
'name': self.name,
}
return (
self.__class__.__qualname__,
[],
kwargs
)
def state_forwards(self, app_label, state):
model_state = state.models[app_label, self.name_lower]
model_state.bases = (models.Model,)
state.reload_model(app_label, self.name_lower, delay=True)
def database_forwards(self, app_label, schema_editor, from_state,
to_state):
pass
def database_backwards(self, app_label, schema_editor, from_state,
to_state):
pass
def describe(self):
return "Remove bases from the model %s" % self.name
@property
def migration_name_fragment(self):
return 'remove_%s_bases' % self.name_lower
- [Django]-Django cannot import name x
- [Django]-Django — How to have a project wide templatetags shared among all my apps in that project
- [Django]-Which database engine to choose for Django app?
0👍
You may have to run makemigrations
for the apps without migrations.
In my case django_quiz
depends on multichoice
, true_false
and essay
.
I had to makemigrations
for each of these before I could migrate
django_quiz.
- [Django]-Using Django Managers vs. staticmethod on Model class directly
- [Django]-React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)
- [Django]-Django-allauth: Linking multiple social accounts to a single user
0👍
I think in my case, I just deleted the parent model inherited by the child model, let us I have CustomUser model and Inherited by Employee model, Before I deleted the employee migration, I was in error same with yours, But After I deleted it worked
- [Django]-Change a form value before validation in Django form
- [Django]-How does Django handle multiple requests?
- [Django]-Select DISTINCT individual columns in django?