in this question I learned how to make two Django projects use the same database. I have:
projects
project_1
settings.py
...
project_2
settings.py
...
and
# project_1/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
},
}
# project_2/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(
os.path.dirname(os.path.dirname(PROJECT_ROOT)),
'project_1',
'development.db'
),
},
}
In project_2/, when I run:
python manage.py syncdb
I get:
django.db.utils.OperationalError: table "auth_permission" already exists
I guess this happens because python fails in trying to add project_2 tables that already exists in the shared db.
How can I add to the shared db only those project_2 tables not already existing in the common database?
EDIT:
After telling project_2/ to use project_1/ db, I run the syncdb and get the existing table error. I do not have a migration file.
Shall I run a different command before syncing?
You can open the migrations file and comment out the SQL that tries to create the table.
Then run migrations again.
(another possibility would be to delete the table in the database, but you'd lose the data in the table.)
Django 1.8.15 for project_2/. I've just checked project_1/ django version and it is 1.6. I was convinced that both projects where using the same django version.. Is this the main problem?
Yes. Because django 1.6 and django 1.8 use different syncdb commands. syncdb in 1.8 is migrate, so when you do syncdb in 1.8 you are applying migrations, not just creating tables. Use same django version and problem should be solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With