I've seen quite some posts about this but none helped me so far. I have a working django application and I want to go from sqlite to postgresql database. For that, I am following the djangogirls tutorial which is great, until some error occurs.
I have downloaded postgresql on my pc for development, then I downloaded and installed psycopg2 which is working fine, I changed my settings.py DB config, and I am at the point where I want to migrate to postgres.
All they say in the tutorial is to run "python manage.py migrate", which did not work for me, probably because they consider it is a blank application or something, and mine already has migrations and models associated to it.
I read that running
python manage.py makemigrations
python manage.py migrate
would do the trick, but I had a problem with my custom model. I then read that I could comment out all the code that used this problematic model, then run
python manage.py makemigrations
python manage.py migrate --fake
uncomment, and run
python manage.py migrate
Which I tried, but now I'm getting the same error as my custom model but for the contenttypes app.
The traceback is this:
("la relation 'django_content_type' n'existe pas" = "the relation 'django_content_type' does not exist")
Operations to perform:
Apply all migrations: auth, contenttypes, sessions, admin
Running migrations:
No migrations to apply.
Traceback (most recent call last):
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: ERREUR: la relation « django_content_type » n'existe pas
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\contrib\contenttypes\models.py", line 67, in get_for_model
ct = self.get(app_label=opts.app_label, model=opts.model_name)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\query.py", line 381, in get
num = len(clone)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\query.py", line 240, in __len__
self._fetch_all()
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\query.py", line 52, in __iter__
results = compiler.execute_sql()
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\models\sql\compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ERREUR: la relation « django_content_type » n'existe pas
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
^
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\core\management\sql.py", line 50, in emit_post_migrate_signal
using=db)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\dispatch\dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\contrib\auth\management\__init__.py", line 85, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "C:\Users\gbastien1\Envs\django-carte\lib\site-packages\django\contrib\contenttypes\models.py", line 80, in get_for_model
"Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
My migrations look like this:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
I have no idea how to solve this problem since I tried so many things. And databases and deployment are not my strong points. Can somebody help me figure this out please?
EDIT I tried reverting all my changes to the part where my application worked and start over by deleting my sqlite file and all my migrations, I deleted all my pyc (python cache) files, commented out all the code related to the Ecole model, and then migrate again, and I still got the same error :(