bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema' #522

Open emilany opened 6 years ago

emilany commented 6 years ago

Hello. I followed what was stated in the installation docs but have come across this:

File "/Users/user/virtualenvs/hrmod/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema'

I have set the db engine as well. 'ENGINE': 'tenant_schemas.postgresql_backend',

I am running on django 1.11. What could possibly be the problem? Thank you.

dstauble commented 6 years ago

@emilany, Did you ever figure this out? I'm having the same issue.

dstauble commented 6 years ago

For anyone receiving this error: My solution was finding a leftover DATABASES/ENGINE assignment pointing to the standard PostgreSQL backend in a separate settings.py file that was being imported (develop vs production). Once I removed the second DATABASES definition, the error was gone.

csailer commented 6 years ago

When I debug the 'makemigrations customer' command it works fine, creates the migrations. When I execute the 'makemigrations' command with python manage.py makemigrations customer from the command line, I get DatabaseWrapper has no attribute schema_name.

SteJ13 commented 3 years ago

I need to replace tenant model with static json data. Is that possible. The reason is i don't want to handle any database. I am going to use third party api. so when i try to command tenant model in settings and do migrate schemas i got 'critical error: Tenant model should set'. Than i called my data.json file in tenant model of settings file like this 'TENANT_MODEL = "app.data" '. when i try to migrate schemas i got the following error.

[standard:public] === Running migrate for schema public Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/django/core/management/init.py", line 381, in execute_from_command_line utility.execute() File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/django/core/management/init.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, *cmd_options) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(args, **options) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/tenant_schemas/management/commands/migrate_schemas.py", line 32, in handle executor.run_migrations(tenants=[self.schema_name]) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/tenant_schemas/migration_executors/base.py", line 58, in run_migrations run_migrations(self.args, self.options, self.codename, public_schema_name) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/tenant_schemas/migration_executors/base.py", line 30, in run_migrations connection.set_schema(schema_name) File "/home/joseph/stej_temp/hgp/env/lib/python3.7/site-packages/django/db/init.py", line 28, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item) AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema'

minu93 commented 3 years ago

I've the same error, does somebody has a solution for that?

bhuwanpaudelofficial commented 10 months ago

i used this

DB_ENGINE=django.db.backends.postgresql

then i got the this error connection.set_schema(schema_name, tenant_type=tenant_type, include_public=False) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema' then i update the the database engine

DB_ENGINE=django_tenants.postgresql_backend

then this problem is solve by updating the code