I've an app named Attendance and it contains the following migrations applied in postgresql db.
attendance
[X] 0001_initial
[X] 0002_delete_leave
[X] 0003_alter_holiday_options_alter_shift_options
[X] 0004_delete_holiday_alter_shift_holidays
[X] 0005_delete_shift
[X] 0006_initial
[X] 0007_alter_leave_options
[X] 0008_alter_leave_comment_alter_leave_is_regularized
[X] 0009_attendance
[X] 0010_alter_attendance_options_attendance_created_at_and_more
[X] 0011_attendance_status
[X] 0012_attendance_is_regularized
[X] 0013_alter_attendance_is_regularized
[X] 0014_remove_attendance_date_attendance_start_date_and_more
[X] 0015_attendance_end_date
[X] 0016_alter_attendance_end_date
[X] 0017_alter_attendance_end_date_and_more
[X] 0018_leavetype_remove_leave_half_day_and_more
[X] 0019_leave_leave_type
when I run python manage.py migrate
with or without app label it does not create tables in db.
I've not set managed=False
and tried to delete all migrations from django_migrations
table but no luck.
One more point I forgot to add that I'm using django-tenants
To debug the issue, I deleted my local database and kept migrations. Before migrating I ran migrate command with --plan
flag
python manage.py migrate --plan
Above command gives me this error
[standard:public] Change Meta options on todo
[standard:public] todo_task.0004_todo_created_at_todo_updated_at
[standard:public] Add field created_at to todo
[standard:public] Add field updated_at to todo
Traceback (most recent call last):
File "env\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "tenant_tenant" does not exist
LINE 1: SELECT "tenant_tenant"."schema_name" FROM "tenant_tenant" WH...
...
I found the issue, according to the documentation. All the apps that we want to have their tables in the public schema, we've got to add them to SHARED_APPS
.
So I added attendance
and task
apps in SHARED_APPS
.
SHARED_APPS = (
'django_tenants', # mandatory
'attendance',
'task',
'django.contrib.contenttypes',
# everything below here is optional
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
)
After this, I deleted my local database, created a new one, and ran the migrate command.
python manage.py migrate
It worked!
Thanks to all who tried to help me (: