I am trying to build some DB front-ends using Django since I like the general MVC structure as well as their template system and admin interface. However, I am having trouble with certain aspects of using a PostgreSQL back-end.
I've managed to figure out how to specify different schemas (and databases) using the database section of the settings.py
file like so:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'MPS': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'OPTIONS': {
'options': '-c search_path=django'
},
'NAME': 'sandbox_manzer',
'HOST': '192.168.2.151',
'PORT': '5434',
'USER': '******',
'PASSWORD': '**********************',
}
}
However, when I try and script some basic tests, as detailed here, I run into a problem. My user can create databases just fine so my test_db gets built, but when the django app goes to build the models into tables I get an error stating that No schema is specified
for the test_db. Any help in how I specify schema names for the test_db would be most appreciated. Especially since I intend to build out multiple apps for a single project using different schemas as logical separators.
Thanks!
PostgreSQL ALTER SCHEMA statement overviewALTER SCHEMA schema_name RENAME TO new_name; In this syntax: First, specify the name of the schema that you want to rename after the ALTER SCHEMA keywords. Second, specify the new name of the schema after the RENAME TO keywords.
A schema in a SQL database is a list of logical data structures. It's commonly used for security-related management and permissions. The feature is supported by PostgreSQL and very well by Django.
I suppose you are familiar with the concept of PostgreSQL schemas.
Your app is looking for the django
schema in your database (which presumably isn’t there) because you have specifically told it so.
'options': '-c search_path=django'
For each application, create a suitably named schema and specify it in the search_path
.
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