0

My Django, SQLlite website is up and running remotely, thanks to all the help here. Now I wanted to migrate my data as well, I have tried several options provided in this forum, however, I have not been able to migrate the data yet

Steps given in the following links have been able to fix my all issues, (none of the other options were able to help me completely)

What's the best way to migrate a Django DB from SQLite to MySQL?

and

Changing Django development Database from the default SQLite to PostgreSQL

However, the remote website is still not showing any data.

=============================================================

HP@HP-PC MINGW64 ~/git_projects/django_local_library (master)

$ python manage.py migrate --run-syncdb

Operations to perform:

Synchronize unmigrated apps: messages

Apply all migrations: admin, auth, catalog, contenttypes, sessions

Synchronizing apps without migrations:

Creating tables...

Running deferred SQL...

Running migrations:

No migrations to apply.


HP@HP-PC MINGW64 ~/git_projects/django_local_library (master)

$ python manage.py shell

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)

from django.contrib.contenttypes.models import ContentType ContentType.objects.all().delete() (56, {'auth.Group_permissions': 0, 'auth.User_user_permissions': 0, 'auth.Permission': 45, 'contenttypes.ContentType': 11}) quit()


HP@HP-PC MINGW64 ~/git_projects/django_local_library (master)

$ python manage.py loaddata datadump.json

Installed 232 object(s) from 1 fixture(s)

=============================================================

After above steps, (with some, unique constraint issues, due to my multiple loads), it appears to me like everything is fine and I was expecting to see my data, however, it is not yet there.

(Just to add, I am able to see my data locally on psql- so the migration is successful, but locally)

Please help me, if I am missing any steps? Or should I try pushing data to heroku?

mamtach
  • 88
  • 3
  • 13
  • What do you mean “migrate the data”? Migrations create the database structure, I.e. the tables and columns. (and if you wrote data migrations populate the database with initial data). But this has nothing to do with copying the database from one (local) database to another. Normally your local data is just test data and in production you want to start fresh with an empty database. – dirkgroten Sep 11 '19 at 21:08
  • @dirkgroten : This is my first django website and I used Sqllite for quick development and deployment, but Sqllite is not supported by heroku, and as a testing step, I followed steps from mozilla.org,and created data to test the website. After deployment, website looks good, but I do not want to loose my test data. So basically, after installing Posgres db on my local env, and the steps mentioned on above link, I was able to migrate data from Sqllite to Postgre, but don't know how to push same data from local postgre db to remote postgre db (ie on heroku). – mamtach Sep 12 '19 at 05:26
  • Same: dumpdata and loaddata. – dirkgroten Sep 12 '19 at 07:41
  • I tried again, but still can't see any data https://frozen-cove-75307.herokuapp.com/catalog/ – mamtach Sep 12 '19 at 08:21
  • You ssh into your Heroku instance and run dumpdata there? – dirkgroten Sep 12 '19 at 08:25
  • no, I did all these 3 steps one after the other in my git bash ( this is the place from where I deployed the website on Heroku.
    385 python manage.py makemigrations
    386 python manage.py migrate
    387 python manage.py loaddata datadump.json 388 heroku open
    – mamtach Sep 12 '19 at 08:38
  • 1
    loaddata is the only way. It should work. – dirkgroten Sep 12 '19 at 09:22
  • @dirkgroten: Thanks for increasing the confidence, I am hoping I haven't missed out or messed up anything, because I have been trying these steps since last two days. For now I'll create data manually. – mamtach Sep 12 '19 at 09:49
  • 1
    Instead of loaddata you can also create a data migration yourself: create an empty migration and use RunPython to load the json file, loop through the elements in your json and create the objects in the db (with Catalog.objects.create() for example). Then migrate. – dirkgroten Sep 12 '19 at 11:52
  • Sure, I will try this, thank you! – mamtach Sep 12 '19 at 12:48

0 Answers0