0

I am trying to migrate a MySQL-based Django project to PostgreSQL. Unfortunately, all sql/syncdb commands fail as soon as I switch the database backend in settings.py.

python manage.py sql profile w/ MySQL:

BEGIN;
CREATE TABLE `profile_department` (
     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `name` varchar(100) NOT NULL UNIQUE,
     [...]

python manage.py sql profile w/ PostgreSQL (psycopg2):

DatabaseError: relation "profile_department" does not exist
LINE 1: ...nt"."homepage", "profile_department"."gd_id" FROM "profile_d...
                                                         ^

Why does Django behave differently with the two DB backends?

4
  • When looking in the database do you have any tables? Commented Apr 9, 2013 at 13:58
  • Please show create table statement which is execute for Postgres (it is not the one you posted). Commented Apr 9, 2013 at 13:59
  • 1
    Why are you querying from the DB when generating sql? Looks like you have a query that triggers on module load... tut tut... Commented Apr 9, 2013 at 14:00
  • No, the database remains empty – which is expected, as the sql command only prints the SQL statements. – There is no CREATE TABLE statement when the PostgreSQL statement is used – just this error message. – I am not querying from the DB, just trying to create the table in my new (empty) PostgreSQL database (if that succeeds, I'll clean out the DB and issue a syncdb command to load the data from the JSON fixture (created from the MySQL DB using dumpdata). Commented Apr 9, 2013 at 14:59

1 Answer 1

1

Thomas was right, there were indeed two queries buried somewhere in models.py that referred to the Department class:

ROOT_DEPARTMENT = Department.objects.get(pk=14)
FACULTIES = Department.objects.filter(parent=ROOT_DEPARTMENT)

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.