I'm getting the error above when setting up my website with apache &mod_wsgi.
I've gone through all of the documentation managed to it half working. Here is the full error:
Exception Type: DatabaseError
Exception Value: no such table: pages_page
I know there is nothing wrong with the DB as before i set the site up with mod_wsgi i could run the site with ./manage.py runserver and it would all work fine.
I have to be carefull what code I post for security perposes.
More than happy to post more information if you tell me you need but i don't really know what to post up as the site itself works fine.
Got it working. I was missing the DJANGO_SETTINGS_MODULE variable from the settings.py file so the apache file was looking for it, but it didn't exist.
Thanks for your replies
There is something wrong with the DB.
When given a nonexistent file name, SQLite will create a new, empty database; and when given an empty file name, SQLite will create a temporary database.
Check that the database file name is configured correctly, and that it's accessible by the web server.
Related
Here is a brief backstory. I am using the Mezzanine CMS for Django. I created some models that inherited from the Mezzanine models. This caused an issue in my Postgres database, where one object was present in two tables. When I would try searching my site for a post, I would not get results from one table.
So, here is where I believe I messed up. I reverted my models to how they were before this issue. This meant that there was still a table in my database for those models, so my search function still wouldn't work. I wanted this relation gone, so I did something very stupid and deleted the entire database. This was fine for my local development, because I just recreated the database and migrated.
When I try deploying this project of mine with the newly created postgres database onto DigitalOcean, I get to this command:
$ python manage.py createdb --nodata --noinput which gives me the error:
psycopg2.errors.UndefinedColumn: column "page_image" of "pages_page" relation does not exist
LINE 1: UPDATE "pages_page" SET "page_image" = '', "keywords_string"...
I looked up a few threads on this error, and tried this solution that did not work:
python manage.py shell
>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.all().delete()
I have also tried the suggestion in the error LINE 1: UPDATE "pages_page" SET "page_image" = '', "keywords_string".... The weird thing was, I saw the page_image column inside the pages_page table before running this command.
I do not know what code may be helpful in this case. I do not know how to troubleshoot this issue. How can I further troubleshoot this issue of mine?
I figured this issue out. It has something to do with the EXTRA_MODEL_FIELDS option in the settings.py file. I'm still not sure why that causes an issue, but here is my EXTRA_MODEL_FIELDS code:
EXTRA_MODEL_FIELDS = (
(
...,
(
"mezzanine.pages.models.Page.page_image",
"ImageField",
(_("Featured Image"),),
{"blank": True, "upload_to": "uploads/blog"},
),
...
)
What I did that caused my issue to go away is as listed below:
I deployed with the createdb --nodata --noinput command commented out.
I continued the deployment process
Once I got to deploying the website, I just ran migrations again
The page_image column was automatically added
Now everything works fine! I don't know how much help this answer might be, but I can always go more into depth if someone wants to chat about their issues.
Django- Why I am getting this Programming Error When I have not declared shop_product variable anywhere .
Please help Click here to view error Image
please refer to this image of error
shop_product is the name of the database table for the model Product in the application shop.
Most likely cause for this error is that you didn't apply database migrations, or, if you did, that you didn't add the application shop to your INSTALLED_APPS.
Update:
According to one of your comments, you are trying to use SQLite, which you cannot use on Heroku, see https://devcenter.heroku.com/articles/sqlite3
But it seems you figured that out because according to the settings of your app, you are using PostgreSQL, but you have not applied your migration.
Migrations are created once with manage.py makemigrations, but you have to apply them on every database, i.e. both on your local dev environment and on the database your application running on Heroku uses. For the latter, try this:
heroku run python manage.py
From the partial SQL query in the image it seems that "shop_product" is a table.
Note:
LINE 1: ... "shop_product"."id" FROM "shop_product"
Check your models if you have ShopProduct model, and check if you have migrations are updated.
Check if you have ManyToMany fields that might create that table, and also check if migrations are up to date.
When using the Django Admin panel, I am able to add new instances to Users and Groups. The same thing goes for all my apps, except for one. This one app, resultregistration, always gives me a ProgrammingError whenever I try to add a new model. For example, this app has a Competition-model where data about a sport competition should be stored.
When I click "+ Add" I am taken to the correct site where I can add a new competition. However, when I press save I get:
ProgrammingError at /admin/resultregistration/competition/add/
column "competition_category" of relation "resultregistration_competition" does not exist
LINE 1: INSERT INTO "resultregistration_competition" ("competition_c...
Of course, I assume something is wrong with the migrations. However, I have run python manage.py makemigrations appname, and python manage.py migrate appname, and that works fine. I get a message that there are "No changes detected", and "No migrations to apply".
I have tried solutions posted on SO, but none of them worked.
What is the general reason for this error? And does anyone know what could be wrong in this specific case? Could one get this error if something is wrongly defined in the model? Or does it have to be a migration problem?
Thank you so much! Any help would be truly appreciated. Also, I am using PostgreSQL, if that helps.
Make sure you have _ init _.py file under the migrations folder for that paticular app.
Running manage.py makemigrations always makes a migration file if there are any changes in your models.py
If nothing works and there isnt much data present in your database, end resolution is to delete all migrations files (if any) for that app or for the project, in terminal type "sudo -su postgres" then type "psql".
Drop your database and create a new one. Run manage.py makemigrations to check if migration file has been created or not. Then migrate with manage.py migrate
I have been using Django for the past 2 years with no issues at all, I am no rookie.
I recently created a new attribute for a model and added it to the mysql database.
Whenever I filter things using this attribute in my "views.py" i get an empty set, whenever I use the same exact line of code using "manage.py shell" it returns the expected queryset.
I have tried restarting the httpd service, the mysqld service and I have rebooted the system but nothing happens.
Does anyone know how to bypass this issue?
Here's the code I used to debug this issue:
Shell:
It won't let me post pictures so here's the code:
>>>Session.objects.filter(cancellation_session=True)
>>>[<Session: Zumba Toning (Ladies)>]
views.py:
def gym_day2(request):
return HttpResponse(str(Session.objects.filter(cancellation_session=True)))
HttpResponse:
[]
Please Help!
add . values or .values_list() after the statement , Session.objects.filter(cancellation_session=True).values(´field´)
I am running a site live on heroku. My issuse occurs when I visit my site's admin located at www.mysite.com/admin. When I visit this page, I get
DoesNotExist at /admin/
Site matching query does not exist.
Thing is, my project /admin works locally as well as on my staging server. It just so happens when I visit it live, I get that error.
After looking around SOF, I tried doing running python manage.py shell with the following commands:
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.xxx.com', name='xxx.com')
and I changed SITE_ID = 1 to SITE_ID = www.mysite.com and that just ended up breaking my staging server, so I changed it back and tried again without changing the SITE_ID.
What could be the issue?
It seems the SITE_ID setting in your settings file is pointing to an ID that doesn't exist in your database.
You either need to create a new site in the sites model (via admin) and change the ID in the settings file to match that one, or re-insert the item via SQL and give it the same ID as your settings file.
This problem will always seem to occur continually, so if you don't want to serve your model with multiple sites, then I suggest you remove the SITE_ID from the setting file. Note this worked for me!
I just had to remove the 'django.contrib.sessions' from INSTALLED_APPS in settings.py as it was causing problems and I was using this project only for one site.
However, if you are using your project for multiple different sites and need the Django sites framework, please check SITE_ID in your database and if it matches the one defined in the settings.