16👍
I didn’t like the idea of commenting/uncommenting code, so I tried a different approach: I migrated “manually” some apps, and then run django-admin.py migrate
for the remaining ones. After deleting all the *.pyc
files, my sequence of commands was:
$ django-admin.py migrate auth
$ django-admin.py migrate contentypes
$ django-admin.py migrate sites
$ django-admin.py migrate MY_CUSTOM_USER_APP
$ django-admin.py migrate
where MY_CUSTOM_USER_APP
is the name of the application containing the model I set AUTH_USER_MODEL
to in my settings
file.
Hope it can help. Btw, it seems strange that the best way to synchronize your db in Django 1.8 is so complicated. I wonder if I’m missing something (I’m not very familiar with Django 1.8, I used to work with older versions)
11👍
Working on Django 1.10 I found out another solution:
My application is named “web”, and first I call:
python manage.py makemigrations web
then I call:
python manage.py makemigrations auth
then I call:
python manage.py migrate
Amazed: IT’S WORKING! 🙂
It seems auth was searching for the AUTH_USER_MODEL “web.UserProfile” and a relation named web_user_profile, and it didn’t find it, hence the error.
On the other hand, calling makemigrations web first creates the required relation first, before auth is able to check and alert it’s not there.
- [Django]-Django: Assigning variables in template
- [Django]-Django return file over HttpResponse – file is not served correctly
- [Django]-Class Based Views VS Function Based Views
8👍
Always migrate db with python manage.py makemigrations
and then python manage.py migrate
in newer versions. For the error above if first time your are migrating your database then use python manage.py migrate --fake-initial
. See docs https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-migrate
- [Django]-How to add superuser in Django from fixture
- [Django]-Python Django: You're using the staticfiles app without having set the STATIC_ROOT setting
- [Django]-Download a remote image and save it to a Django model
6👍
I had the same problem, and I spent hours banging my head trying to find a solution, which was hidden in the comments. My problem was that CircleCI couldn’t run tests because of this error. And I thought I would need to start fresh with a new and empty DB. But I got the same errors. Everything was seemingly related to ‘auth’, ‘contenttypes’ and ‘sites’.
I read this, and this, as well as this and also this. None were solutions for me.
So after having destroyed my DB and created a new one, the only solution I found to entirely avoid these django.db.utils.ProgrammingError
was to:
- Comment out all code related to the
User
model. - Delete all .pyc files in my project!
find . -name "*.pyc" -exec rm -- {} +
Thanks @max! - run
./manage.py migrate
(no fake, no fake-initial, no migration of ‘auth’ or ‘contenttypes’ before, juste plain migrate. - Uncomment the above code, and run migrate again!
My INSTALLED_APP is the following:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'mptt',
'djangobower',
'honeypot',
'django_hosts',
'leaflet',
'multiselectfield',
'corsheaders',
'rest_framework_swagger',
'allauth',
'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.twitter',
# 'allauth.socialaccount.providers.facebook',
'project.<app_name>',
)
- [Django]-Cannot import name _uuid_generate_random in heroku django
- [Django]-Django javascript files
- [Django]-User Authentication in Django Rest Framework + Angular.js web app
2👍
Deleting migration files, associated .pyc files, and just to be safe all .pyc files with the following commands did not solve my issue.
$ find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
$ find . -path "*/migrations/*.pyc" -delete
$ find . -name "*.pyc" -exec rm -- {} +
What ended up solving my issue wasn’t clearing caches, it was because I had a function that performed a query as a default function parameter. On init, which is what commands like makemigrations
and migrate
do before executing it seems like django (perhaps a python attribute?) initializes all default parameters.
As my database was completely empty (I needed to perform migrate --run-syncdb
to recreate the tables) when the below default parameter was initialized, it ran a query against the empty database that subsequently failed.
change this:
def generate_new_addresses(number=1, index=None, wallet=get_active_wallet()):
...
...
return
to:
def generate_new_addresses(number=1, index=None, wallet=None):
if not wallet:
wallet = get_active_wallet()
...
...
return
- [Django]-UUID as default value in Django model
- [Django]-Accessing image dimensions on an ImageField in a Django template?
- [Django]-How to add a sortable count column to the Django admin of a model with a many-to-one relation?
2👍
I had the same issue, but my underlying cause was the __init__.py
file in one of the migrations folders had been deleted from source code but not locally (causing ‘Not on my machine’ errors).
Migrations folders still need __init__.py
files, even with Python 3.
- [Django]-How to manually assign imagefield in Django
- [Django]-Python vs C#/.NET — what are the key differences to consider for using one to develop a large web application?
- [Django]-Django logging on Heroku
1👍
In my case, this error was appearing when the postgresql driver was able to connect to the database, but the provided user does not have access to the schema or the tables, etc. Instead of saying permission denied, the error being shown is saying that the database table being queried is not being found. Typically in such a situation, the migrate command will also fail with a similar error when it tries to create the django_migrations
table.
Check for access being granted on the user you’re using in database connection in Django.
- [Django]-Django query negation
- [Django]-Manager isn't accessible via model instances
- [Django]-Difference between different ways to create celery task
0👍
I had this issues with a forms.ChoiceForm
queryset. I was able to switch to using forms.ModelChoiceForm
which are lazily evaluated and this fixed the problem for me.
- [Django]-Django ManyToMany model validation
- [Django]-Django: Unable to load template tags
- [Django]-Using django signals in channels consumer classes
0👍
In My Case
I made migrations using some other similar looking migration file(1).
Then I deleted it, and made 2 new migration files for replacement(2&3).
And then I was getting this error.
In my case the table was renamed using migration file 1
But django was searching for old table name in migration file 3
So I renamed table manually to old name, and applied migration and It was successful
- [Django]-Retrieving list items from request.POST in django/python
- [Django]-Django – getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-Why doesn't this Django logging work?
0👍
I was also facing the same issue, I’d already created the table but it was still showing that the table does not exist.
A simple solution to this is, Just to delete the database of your PostgreSQL and all migration files in your Django project. After deleting run
python manage.py makemigrations app_name
python manage.py migrate
- [Django]-Django string to date format
- [Django]-How to add url parameters to Django template url tag?
- [Django]-Django Order By Date, but have "None" at end?
-1👍
Error is basically because db (postgres or sqlite) have not found the relation, for which you are inserting or else performing CRUD.
The solution is to make migrations
python manage.py makemigrations <app_name>
python manage.py migrate
- [Django]-What is the path that Django uses for locating and loading templates?
- [Django]-Tell if a Django Field is required from template
- [Django]-ProgrammingError: relation "django_session" does not exist error after installing Psycopg2