django-tenant-schemas icon indicating copy to clipboard operation
django-tenant-schemas copied to clipboard

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

Open emilany opened this issue 7 years ago • 6 comments

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.

emilany avatar Jan 08 '18 08:01 emilany

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

dstauble avatar Mar 07 '18 16:03 dstauble

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.

dstauble avatar Mar 07 '18 16:03 dstauble

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.

csailer avatar Sep 25 '18 18:09 csailer

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'

SteJ13 avatar Jan 08 '21 06:01 SteJ13

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

minu93 avatar Nov 02 '21 10:11 minu93

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

bhuwanpaudelofficial avatar Jan 12 '24 10:01 bhuwanpaudelofficial