-2

I've been working on a Django project locally and used SQLITE as the database. I've now deployed the project to Heroku-website and used Postgresql as the database. The database schemas have moved over fine but the data from the tables has not migrated.

What is my problem?

Here is my database code from settings file.

    DATABASES = {
        'default': {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
        }
    }

    import dj_database_url
    db_from_env = dj_database_url.config(conn_max_age=600)
    DATABASES['default'].update(db_from_env)
  • This solution worked for me: https://stackoverflow.com/questions/54958008/providing-initial-data-for-models-django โ€“ bananatoast Oct 29 '22 at 10:51
  • "but the data from the tables has not migrated"โ€”of course it didn't. That's not what migrations are for. Data can (and often _should_) vary between environments. โ€“ ChrisGPT was on strike Oct 29 '22 at 14:41

1 Answers1

0

You should use engine name only in database while in production.

In settings.py file:

"ENGINE": "django.db.backends.postgresql_psycopg2"

Transfer data from local to production.

Data transfer

Install the Heroku PGBackups add-on:

heroku addons:add pgbackups

Dump your local database:

pg_dump -h localhost  -Fc library  > db.dump

In order for Heroku to access db dump, you need to upload it to the Internet somewhere.

Import the dump to Heroku:

heroku pgbackups:restore DATABASE http://www.example.com/db.dump
Manoj Tolagekar
  • 1,816
  • 2
  • 5
  • 22