Django migrate schema from sqlite to postgresql

Asked
Active3 hr before
Viewed126 times

5 Answers

migratedjangosqlitepostgresql
90%

Alter settings,py to point to the newly created postgres database,Change DATABASES in settings

Example_snippet/controller/utility/_migrate.js/ $ ./manage.py dumpdata > dump.. . .
$. / manage.py dumpdata > dump.json
Step 2 continued with DATABASES = { # COMMENT OU. . .
DATABASES = {
   # COMMENT OUT: # 'default': dj_database_url.config(
      default = 'sqlite:////full/path/to/your/database/file.sqlite'),
   # ADD THIS INSTEAD: 'default': dj_database_url.config(
      default = 'postgres://localhost:5432/postgres_db_name'),
}
Step 3 continued with $ ./manage.py syncdb $ ./manag. . .
$. / manage.py syncdb
$. / manage.py migrate
Step 4 continued with $ ./manage.py loaddata dump.js. . .
$. / manage.py loaddata dump.json
load more v
88%

SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational Database Management Systems,Well, SQLite and PostgreSQL are the most widely used relational database management systems, They are both open-source and free

Example_snippet/controller/utility/_migrate.js/ python3 manage.py dumpdata > d. . .
python3 manage.py dumpdata > datadump.json
load more v
72%

Change settings,py to Postgres backend

Example_snippet/controller/utility/_migrate.js/ python3 manage.py dumpdata > d. . .
python3 manage.py dumpdata > datadump.json
Step 2 continued with python3 manage.py migrate --ru. . .
python3 manage.py migrate--run - syncdb
Step 3 continued with python3 manage.py shell . . .
python3 manage.py shell
Step 4 continued with >>> from django.contrib.conten. . .
>>> from django.contrib.contenttypes.models
import ContentType
   >>>
   ContentType.objects.all().delete() >>>
   quit()
Step 5 continued with python3 manage.py loaddata dat. . .
python3 manage.py loaddata datadump.json
load more v
65%

Copy all the data from a sqlite database into a postgresql database in Django, ,We will dump all the data from the sqlite database with the command3 manage

Example_snippet/controller/utility/_migrate.js/ $ ./manage.py dumpdata --inde. . .
$. / manage.py dumpdata--indent 4 > dump.json
Step 2 continued with $ ./manage.py migrate Operati. . .
$. / manage.py migrate
Operations to perform:
   Apply all migrations: admin, auth, contenttypes, games, sessions
Running migrations:
   Applying contenttypes .0001_ initial...OK
Applying auth .0001_ initial...OK
Applying admin .0001_ initial...OK
Applying admin .0002_ logentry_remove_auto_add...OK
Applying admin .0003_ logentry_add_action_flag_choices...OK
Applying contenttypes .0002_ remove_content_type_name...OK
Applying auth .0002_ alter_permission_name_max_length...OK
Applying auth .0003_ alter_user_email_max_length...OK
Applying auth .0004_ alter_user_username_opts...OK
Applying auth .0005_ alter_user_last_login_null...OK
Applying auth .0006_ require_contenttypes_0002...OK
Applying auth .0007_ alter_validators_add_error_messages...OK
Applying auth .0008_ alter_user_username_max_length...OK
Applying auth .0009_ alter_user_last_name_max_length...OK
Applying auth .0010_ alter_group_name_max_length...OK
Applying auth .0011_ update_proxy_permissions...OK
Applying auth .0012_ alter_user_first_name_max_length...OK
Applying games .0001_ initial...OK
Applying games .0002_ auto_20200825_1236...OK
Applying games .0003_ auto_20200825_1326...OK
Applying games .0004_ auto_20200825_1413...OK
Applying games .0005_ auto_20200825_1416...OK
Applying games .0006_ auto_20200825_1635...OK
Applying games .0007_ auto_20200825_1635...OK
Applying games .0008_ auto_20200825_1652...OK
Applying games .0009_ auto_20200825_1705...OK
Applying games .0010_ auto_20200825_1900...OK
Applying games .0011_ auto_20200828_1851...OK
Applying games .0012_ auto_20200828_1852...OK
Applying games .0013_ auto_20200828_1907...OK
Applying sessions .0001_ initial...OK
$
Step 3 continued with $ ./manage.py loaddata dump.j. . .
$. / manage.py loaddata dump.json
Installed 153 object(s) from 1 fixture(s)
Step 4 continued with django.db.utils.IntegrityError. . .
django.db.utils.IntegrityError: Problem installing fixture 'local_datadump.json': Could not load contenttypes.ContentType(pk = 3): duplicate key value violates unique constraint "django_content_type_app_label_model_XXXXXX_uniq"
DETAIL: Key(app_label, model) = (admin, logentry) already exists.
Step 5 continued with $ ./manage.py dumpdata --natu. . .
$. / manage.py dumpdata--natural - foreign--exclude auth.permission--exclude contenttypes--indent 4 > data.json
load more v
75%

Run a migrate command to create your tables,Change your DATABASE settings,Create the role you’re going to use,Migrating any existing data from sqlite to your Postgresql database,

Example_snippet/controller/utility/_django.js/ dumpdata. . .
dumpdata
load more v