0
votes

I did my django dev on SQlite and now I am trying to run my apps with postgres 9.5.

However when I run migrate I am getting this error django.db.utils.ProgrammingError: relation "django_content_type" does not exist

. I am using django 1.8 and python 2.7 and getting it when doing migration , when running -fake initial getting same error.

I am looking at existing answers (this problem is common) but I dont see clear answer that works for me.

> (mrp) C:\Users\I812624\dev\mrp\src>python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: django_filters, autofixture, staticfiles, message
s, smart_selects, watson, django_select2, django_countries, mptt, psycopg2, main
, crispy_forms
  Apply all migrations: customer, manufacture, product, vendor, purchase, admin,
 sessions, sales, flatpages, sites, item, contenttypes, production, auth, regist
ration, inventory
Synchronizing apps without migrations:
  Creating tables...
    Creating table watson_searchentry
    Running deferred SQL...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 441, in execute
    output = self.handle(*args, **options)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)

  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 317, in sync_apps
    cursor.execute(statement)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
 line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
 line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\utils.py", line 97,
 in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
 line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
3
there are really two parts to your problem: 1) how do you recreate the table structure? 2) how do you move over your current data? If you simply change your database settings and run manage.py migrate, what happens? After that runs successfully you will have to find a way to migrate the data in your SQLite tables. Again Google will probably be your friend.Colin Nichols
I simply created postgres locally changed the settings of DB. delete previous migrations and manually run makemigration for each app. Then after i run migrate I am getting the error from the question. (Added trace from the shell to the question)Ilya Bibik
And I dont need to migrate the content , just the structure.Ilya Bibik

3 Answers

1
votes

Your DATABASES section in settings.py should be like:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'yourdb',
        'USER': 'youruser',
        'PASSWORD': 'yourpass',
        'HOST': '',
    },
}

Your INSTALLED_APPS should include psycopg2 Once this in place and server restarted, you can remigrate, which should create the missing table

0
votes

django_content_type should be created automatically. I'm wondering how did you do your makemigrations Maybe try

python manage.py makemigrations

instead of doing them one by one

0
votes

So after playing around it started to work. Solution was that I havent added the server to pgAdmin https://www.pgadmin.org/

I was under assumptions that pgadmin is just a tool to see whats going on but without adding postgre to pgadmin the migration had errors.