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
Related
We three working with Django and postgres is the database. Whenever we push the code to GitHub. The database data is not reflecting. The data I stored is visible to me only. The postgres user, password and database name are same on all our laptops. How to make when I push that has to go their databases also.
If you are talking about changes in db schema, then take a look django migrations - https://docs.djangoproject.com/en/3.1/topics/migrations/. The workflow is following:
change model (e.g. add new field, change existing field...)
generate migration file by running python manage.py makemigrations. This generates migration file in <app_folder>/migrations
Run python manage.py migrate to apply changes in models to your database
Add migration file to your version control (github or whaever) and push it
Now when your colleagues gets updated code from version control they need to run python manage.py migrate to apply model changes to their local database.
I found that it is not possible to send postgress data directly. But sqlite can be used for it. This link aids in that - https://manuelvanrijn.nl/blog/2012/01/18/convert-postgresql-to-sqlite/ . But i send data by taking backup like
From Postgres to Postgres: taking backup :
pg_dump dbname > dbname.bak
and then on new Postgres restored with:
psql test < dbname.bak
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.
I have a django based herokuapp site. I set everything up a long time ago and am now unable to get things working with a local instance of postgresql. In my settings file, I updated:
DATABASES['default'] = dj_database_url.config()
to work with a local database:
DATABASES['default'] = dj_database_url.config(default='postgres://localhost/appDB')
When running foreman, I can view the site, but the database is not currently populated (although I did create the empty DB). Running:
heroku run python manage.py dumpdata
Returns the contents of the remote (herokuapp) database, while a syncdb command results in "Installed 0 object(s) from 0 fixture(s)". So it looks like I'm still contacting the remote database. I'm pretty sure the postgresql DB is setup correctly locally; how can I force the app to use it?
I'm sure this is simple, but I haven't seen anything useful yet. I did try
export DATABASE_URL=postgres:///appDB
but that hasn't helped.
Cheers
Im following the getting started with Django on Heroku - and it shows to set up dj_database_url...
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Am I supposed to leave this exactly as above? thats what I did - and my site appears to work just fine...
OR
Am I supposed to swap out something in the above with DATABASE_URL - which gets pulled from the heroku config set ups?
With not using DATABASE_URL anywhere -- it appears to be working on heroku with the above set up and no change.... but when I look at the DB with a pg:info - I get 0 connections... which makes me think there is no connection to the postgresql -- but hows it working then??
I don't quite understand yet how dj_database_url is working on Heroku with this...can anyone shed a bit more light on this?
heroku pg:info
=== HEROKU_POSTGRESQL_GOLD_URL (DATABASE_URL)
Plan: Dev
Status: available
Connections: 0
PG Version: 9.1.6
Created: 2012-10-07 16:11 UTC
Data Size: 6.6 MB
Tables: 12
Rows: 27/10000 (In compliance)
Fork/Follow: Unavailable
It is correct as-is.
When running on Heroku, there is an environment variable set (DATABASE_URL) which contains the database URL (a string like postgres://, but with a long autogenerated username/password/database-name, and the host is on amazonaws usually)
When running locally, DATABASE_URL is not set, so your default = '...' database URL is used instead (allows you to run the code locally for development, and deploy to Heroku, without changing any code).
This is based on the "12factor methodology" (the whole document pretty much describes how Heroku is structured)
The dj_database_url.config just parses the username/password/host/db-name from the URL, and splits it into the dictionary format expected by Django - the code is rather simple, if you are curious
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.