[Django]-Getting 'No field found in Account with column name ""' when creating migration initial data in a project using django-multitenant library

2👍

Found out the solution for the problem

When using django-multitenant, we must import classes directly. We shouldn’t get the classes using app.get_model since django-multitenant fails to identify the tenant_id column from the class instance returned from app.get_model
I removed the app.get_model line and added the import statement as below

from ..models import *
Account.objects.using(db_alias).bulk_create([   
    Account(name="johndoe", domain="domain", subdomain="subdomain",     country=Country.objects.get(name="USA")),             
    Account(name="jilldoe", domain="domain", subdomain="subdomain", country=Country.objects.get(name="USA")),             
    Account(name="milldoe", domain="domain", subdomain="subdomain", country=Country.objects.get(name="USA")),             
    Account(name="velidoe", domain="domain", subdomain="subdomain", country=Country.objects.get(name="Turkiye")),             
    Account(name="alidoe", domain="domain", subdomain="subdomain", country=Country.objects.get(name="Turkiye")),             
    Account(name="pierredoe", domain="domain", subdomain="subdomain", country=Country.objects.get(name="France")),         
    ])

Leave a comment