After reading this blog post https://blog.starkandwayne.com/2015/05/23/uuid-primary-keys-in-postgresql/ I wanted to know more about how Django generates uuid because I am using them as my pk. Well, according to the docs, https://docs.djangoproject.com/es/1.9/ref/models/fields/#uuidfield, Django is relying on the Python UUID module https://docs.python.org/3/library/uuid.html#uuid.UUID. But there are many kinds of UUID, and it is not at all clear to me which one is being generated
Tag: postgresql
Error Installing Psycopg2 on MacOS 10.9.5
I’m trying to install Psycopg2 on my Macbook, but I am getting an error. I found a lot of the same questions on StackOverflow but no answer seems to work. I’m using: OS: MacOS 10.9.5 Python Version: 3.4.3 My error code is: Answer I ran pip install psycopg2-binary and it worked like charm More info about the binary package Python
Django change database field from integer to CharField
I have a Django app with a populated (Postgres) database that has an integer field that I need to change to a CharField. I need to start storing data with leading zeros in this field. If I run migrate (Django 1.8.4), I get the following error: I tried searching Google, but didn’t really find much help. I don’t really know
Django 1.8 inspectdb command doesn’t see PostgreSQL views as per documentation
I have a Django 1.8 application with a PostgreSQL database. I run the django inspectdb from the command line to examine models for the views, but the views don’t show up in the model output. Here’s the version output: And here’s what psql sees: From the django 1.8.2 documentation: How can I get the PostgreSQL views to appear in the
Creating transactions with with statements in psycopg2
I am trying to use psycopg2 to add some new columns to a table. PostgreSQL lacks a ALTER TABLE table ADD COLUMN IF NOT EXISTS, so I am adding each column in it’s own transaction. If the column exists, there will be a python & postgres error, that’s OK, I want my programme to just continue and try to add
Installing psycopg2 in a virtualenv in ubuntu os
I using a virtualenv and I am trying to set up postgresql. I have psycopg2 installed on my system, but it appears that my virtual env does not recognize psycopg2. Is it possible to just copy the system wide psycopg2 files into my django project directory or is this a bad approach to take? This is the relevant part of
Can’t access Postgres DB on Heroku app
I have a Python 2.7 / Flask app running on Heroku that scrapes data and I now want to store that information in a database. I’ve tried to follow tutorials like this one and apply this to my case but I can’t get it to work. I have created & promoted my postgres database successfully on heroku. I am fairly
Postgresql Database Backup Using Python
I would like to backup database using Python code. I want to backup some tables of related data. How to backup and how to choose desired tables using “SELECT” statement? e.g. I want to get data from 2014-05-01 to 2014-05-10 of some tables and output this result as .sql extension file How can I get this format using python code?
How to write DataFrame to postgres table
There is DataFrame.to_sql method, but it works only for mysql, sqlite and oracle databases. I cant pass to this method postgres connection or sqlalchemy engine. Answer Starting from pandas 0.14 (released end of May 2014), postgresql is supported. The sql module now uses sqlalchemy to support different database flavors. You can pass a sqlalchemy engine for a postgresql database (see
query from postgresql using python as dictionary
I’m using Python 2.7 and postgresql 9.1. Trying to get dictionary from query, I’ve tried the code as described here: http://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL It is printing the next answer: printing the item itself, show me that it is list. The excepted answer was dictionary. Edit: Trying the next: returns Answer If you don’t want to use a psycopg2.extras.DictCursor you can create a