Django-page-cms deployment insert error - django

and thanks for taking the time to read my question.
I am using django 1.3 with postgresql. I have django-page-cms 1.4.5 installed. I added pages to my installed apps, run manage.py syncdb, and manage.py migrate. On my remote dev server, I can navigate the to admin/pages, and get to the add page form. However, when I try to do the insert (submit the form) I get the following error:
IntegrityError: insert or update on table "django_admin_log" violates foreign key constraint
"django_admin_log_content_type_id_fkey"
DETAIL: Key (content_type_id)=(24) is not present in table "django_content_type".
When I do a select on my django_content_type table, there are three rows for pages:
20 | content | pages | content
21 | pagepermission | pages | pagepermission
22 | pagealias | pages | pagealias
I am able to insert pages on my local dev server. And the id for pagealias in my local db django_content_type is 24.
How did this carry over from local to remote? Shouldn't this be taken from the relevant db? How can I fix this?
Remote: ubuntu, Local: win7
Thank you!

I had actually the same problem with two instances of the database on the remote server. Both were cached by the same instance of memcache and this was the problem.
I could fix it by creating separated instances of memcache, restarting the servers and doing a syncdb.

Related

How to load sql dump in a containerized django docker which depends on postgres

I am running a Django container on docker which depends on Postgres. Now the issue is, when I try to load the postgresql
docker-compose up
cat /tmp/dump.sql | sudo docker exec -i <container_id> psql -U <user> -d <database_name>
This imports the first few tables and gives me a lot of errors on the terminal
An example
constraint "table_id" for relation "table_name" already exists
Another example
null value in column "column_name" violates not-null constraint
Another one
insert or update on table "table_1" violates foreign key constraint "table_id"
I wanted to know is this even the right way to import this data. Plus I cant seem to drop the database as it is already being used by django.
Note:
I tried with volumes where I imported the db with postgresql. But everytime I run django, the database gets reset. I am guessing it has something to do with the migrations, but I can't touch that part.
The issue was being caused because the sql dump was trying to overwrite existing db. A quick solution if you are on dev would be to
docker volume rm <volume_name>.
And then run the cat ... command

django postgres integration error, no such table - auth user

After updating the django settings.py default database to correct values.
i am able to run makemigrations and migrate command and also create super user. but when i login to the admin it gives me error of “no such table - auth user, OPERATIONAL ERROR”.
I noticed that even if i delete db.sqlite3 file, it comes back when i try to login, i think django looks for table in db.sqlite3 and not postgres.
why db.sqlite3 file re appear after deleting ?
how do i correctly configure my settings.py ?
i am integration using digitalocean managed database services with django installed in one droplet, i have integrated both preciously without error but i installed postgres, this is the first time using managed database service.
Thanks
It seems that your django settings are still pointing to the SQlite database.
Did you reload your WSGI process ? If not, the old SQlite settings are still used in memory.

Restoring Django dump

I've been running a daily dump of a production Django application as follows:
./manage.py dumpdata --exclude=contenttypes --exclude=auth.Permission -e sessions -e admin --all > data.json
Normally, restoring this to another installation for development hasn't caused a problem, but recently attempts to restore the data have caused this:
./manage.py loaddata -i data.json
django.db.utils.IntegrityError: Problem installing fixtures: The row in table 'reversion_version' with primary key '1' has an invalid foreign key: reversion_version.content_type_id contains a value '14' that does not have a corresponding value in django_content_type.id.
This suggests to me that the problem has been caused by the recent addition of django-reversion to the codebase, but I am not sure why and I have not been able to find any means of importing the backup. Some posts suggest that using natural keys may work, but then I get errors like:
django.core.serializers.base.DeserializationError: Problem installing fixture 'data.json': [u"'maintainer' value must be an integer."]
"maintainer" is in this case a reference to this bit of code in a model definition in models.py:
maintainer = models.ForeignKey(Organization,related_name="maintainer",blank=True,null=True)
Does anyone has any suggestions as to how I might get this dump installed, or modify the dump procedure to make a reproducible dump?
I note that the production site is using Postgres and the test site has SQLite, but this has never been a problem before.
On your local machine clone your project and do something like this:
Checkout the project at state that was used to create the dump.
Create a new database and tables.
Load the dump.
Update the code to current state.
Run migrations.
That was rather painful. It seems that the way to fix it was to dump django_content_types as csv from the production posgres database, delete the IDs from the resulting csv file, then do the following on the SQLite database for the test version:
CREATE TABLE temp_table(a, b, c)
.mode csv
.import content_type.csv temp_table
DELETE FROM sqlite_sequence WHERE name = 'django_content_type'
DELETE FROM django_content_type
INSERT INTO django_content_type(name,app_label,model) SELECT * FROM temp_table
That had the effect of setting the ids of the entries in the django_content_type table to match those in the dump, allowing the restore to proceed.

Making changes to postgres databse on heroku - django app

Hey Im using heroku for the first time and I made some changes to some models in Django.
This is what I do:
heroku pg:info --app podiium-staging
=== HEROKU_POSTGRESQL_TEAL_URL
Plan: Dev
Status: available
Connections: 0
PG Version: 9.1.11
Created: 2012-10-20 00:57 UTC
Data Size: 9.1 MB
Tables: 61
Rows: 48/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Then:
heroku pg:psql HEROKU_POSTGRESQL_TEAL_URL --app=podiium-staging
---> Connecting to HEROKU_POSTGRESQL_TEAL_URL
psql (9.3.3, server 9.1.11)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
podiium-staging::TEAL=> alter table debate_debate add column debate_image text;
Ok So I thaught I had altered the database, but in django that column does not exist.
So I guess Im making changes to another DB?
Please help me, I am so confused with this sh%T
What are your database settings in settings.py?
Also, have you considered using South for schema changes? It makes it much easier.
http://south.readthedocs.org/en/latest/index.html

Django Simple Captcha: Table not found

On my local development machine I've already successfully installed django-simple-captcha. However, when I run it on the production server, the table is not found, resulting in a TemplateSyntaxError.
Caught DatabaseError while rendering: no such table: captcha_captchastore
I'm using sqlite3 as database engine and had already run python manage.py syncdb and checked the created tables with the following SQL statement:
sqlite> select name from sqlite_master where type = 'table';
auth_permission
auth_group_permissions
auth_group
auth_user_user_permissions
auth_user_groups
auth_user
auth_message
django_content_type
django_session
django_site
django_admin_log
captcha_captchastore
However, even if all the other tables work just fine, captcha_captchastore is not found. What could be possible reasons for this failure and how to fix it?
Additional findings:
When I run the Django development server on the production machine and check back everything works fine. Apparently it has something to do with the way I run Django. I currently have a setup with nginx and Django via fastcgi. The launch command is the following:
python manage.py runfcgi host=127.0.0.1 port=8081 --settings=settings
How can this influence finding the database or not? Probably there is a path problem.
I couldn't find out how the path to databases is constructed when you are in a template environment or in the scope of another app, but setting an absolute path name fixes the issue.