django programming error : column does not exist - django

Hello I am running a django app using Django. The app is working correctly . But when I add a new field in my model.py I got this error
ProgrammingError at /admin/challenges/challenge/
column challenge.category does not exist
LINE 1: ..., "challenge"."modified_at", "challenge"."title", "challenge...
I found similar questions but they didn't solve my problem.
I tried to run "python manage.py migrate" and it doesn't solve the problem
Could any one help me please ?

I think you have not done make migration command. Perform
python manage.py makemigrations
and then use command
python manage.py migrate

Related

Django Rest API - ProgrammingError relation 'core_donation' does not exist

Here is a link to my github repo: https://github.com/hertweckhr1/api_foodcycle
My user endpoints work great. However when I try to reach my endpoint localhost:8000/api/donation/donations, I get back the error:
ProgrammingError at api/donation/donations relation "core_donation" does not exist Line 1: ...n"."pickup_endtime", "core_donation"....:
Link to Error Message
I have tried makemigrations donation and migrate several times. It says my migrations are up to date. Other posts similar to this, I have not been able to find a solution that works for me.
Thanks in advance!
Run these commands
python manage.py makemigrations
python manage.py migrate
Try to delete all stuff in migrations folder(only keep __init__.py file) and after that do migrations again:
python manage.py makemigrations
python manage.py migrate

relation does not exist(postgresql, django)

I'm using django with postgresql. But when I run the app, I get the following error:
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
I searched for this error, but the only situation people talked about was when the name of the table had mixed case characters. But the table name in my case is all in small letters so this shouldn't happen. What is wrong here?
Thanks
p.s.
This is the project I'm working with.
https://github.com/mirumee/saleor
You should just execute the migrate command:
docker-compose exec web python manage.py migrate
Then create superuser:
docker-compose exec web python manage.py createsuperuser
And enter in the new superuser log in.

InconsistentMigrationHistory with django user_auth

I'm working on my first django project and I'm trying to add user_authentication now. I know i probably should've done this at the very start but I'm trying to do it now. I have a few other apps created and its running fine. However when I added an accounts app i get the following error when i run migrations in accounts/models.py
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.
What helped me with migrations in situation where I have problem like:
django.db.utils.ProgrammingError: (1146, "Table 'mydjango.MyApp_publication' doesn't exist").
It's regarded to the connections.py is following:
Run the command python manage.py
migrate --fake MyApp zero
and then python manage.py migrate MyApp.
Here 'MyApp' is the app you're creating on your Django Server.
I delete all tables except ‘auth_user’, and run ‘python manage.py makemigrations myapp’ ‘python manage.py migrate myapp’ again.
This solved the problem.

Django: I get a [relation "auth_group" does not exist] error after syncdb

I started a new Django 1.8 project and realized that I missed something (i had done the initial migrations). I dropped the database (postgreSQL) and deleted migration folders from all my apps in order to start from scratch.
Now, when I 'syncdb' I get this error:
django.db.utils.ProgrammingError: relation "auth_group" does not exist
and when I makemigrations I get this:
No changes detected
What am I doing wrong?
Probably you should try to create migrations modules (folders named migrations with empty file named __init__.py inside of each directory) for your apps. And then run manage.py makemigrations again.
The problem is on no changes detected. Please execute these commands with your app name. I guess you didn't add it (just like the mistake I did):
python manage.py makemigrations myappname
python manage.py migrate myappname
The above error occurs when you have django.contrib.admin among the installed applications.
Run these commands in their respective order.
**
./manage.py makemigrations
./manage.py migrate auth
./manage.py migrate**
That worked for me perfectly.
Doing ./manage.py migrate auth first didn't work for me, and every ./manage.py command was throwing this error. My problem was that I was doing stuff with the Group manager in module scope.
If you have code like this in module scope:
customers_group = Group.objects.get(name='customers')
Move it inside a function that is called at runtime instead.
def xyz():
...
customers_group = Group.objects.get(name='customers')
I had the similar problem with Django2.2 migrations. I will post what helped in case someone is looking to fix this.
I commented out all urls to apps(like my_app.urls, your_app.urls) in main project urls.py and then ran makemigrations, it worked.
I think this error is due to some forms/views referring to model/fields that are not yet created. It seems django traverses urls.py to before making migrations
It can be either:
one of the pip dependencies from requirements.txt was using South
had this error when running tests which do migration in Django 1.8. Found the lib with issue by running tests in verbose mode. Consider upgrading the library to newer version.
manage.py test -v 3
one of the /migrations folder might still has old South migrations files.
It can be because others are still adding migrations when you are trying to upgrade Django. Use the following to make sure that the expected migrations files are present in each app.
manage.py showmigrations
One of your paths ("pointing urls.py on your core folder along with the settings.py") makes that problem occur importing django.contrib.auth and directly using methods and properties of "auth" after calling those views
Remove all migrations except "init.py" of each apps
Go to projects urls.py and comment out all the paths
run "heroku run python manage.py makemigrations"
run "heroku run python manage.py migrate"

What is the best Django syncdb crash debugging technique?

What is the best Django syncdb crash debugging technique ?
I've previously asked a question about a problem with manage.py syncdb returning an exception
and the answer was that the app has a wrong import.
django manage.py syncdb not working?
I'd like to know the technique used to find the place where there is a wrong import.
I tried ./manage.py syncdb --verbosity=2 but I didn't get any more information that way.
You look at the problem the other way around.
syncdb doesnt have anythin to do with "import". You have misconfigured python or/and django install and this is a problem.
If you want to debug what happen with sql queries then you should use
python manage.py sqlall __yourappname__