简体   繁体   中英

How to import an existing database in my Django project?

I'm trying to add an existing sqlite3 database to my Django project but it doesn't seem to be recognized.

I've added that database to my project folder, modified the settings.py file to reflect that addition:

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

I then ran the 'python manage.py makemigrations' and the 'python manage.py migrate' commands but it doesn't seem to do anything. When I run 'python manage.py inspectdb', it only shows the tables within the default database.

What am I missing?

Depends on document:

The migrate management command operates on one database at a time. By default, it operates on the default database, but by providing the --database option, you can tell it to synchronize a different database.

So, you must provide your db name when you make migrate.For detail you can see here

./manage.py migrate --database=added_db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM