-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)
2
  • This solution worked for me: stackoverflow.com/questions/54958008/… Commented Oct 29, 2022 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. Commented Oct 29, 2022 at 14:41

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.