0

I am trying to use Azure SQL with Django by using mssql-django. I get this error during "makemigrations":

django.db.utils.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'customer_group_customergroup'. (208) (SQLExecDirectW); [42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)")

The connection to Azure SQL is already working. If I start a new app, I could make the migrations and migrate it into Azure SQL without problem.

If I migrate only the "customer_group" App, there is no problem. The problem only occurs when I want to migrate apps, whose model contains a foreign key field named customer_group. I tried renaming the field (suspecting it was some naming conflict) but the error still persists.

Does anyone know how to correct this error? Thank you!

Edit: My customer_group app has this model:

class CustomerGroup(models.Model):
    name = models.CharField(max_length=50, unique=True, blank=False, null=False,
                            verbose_name="Customer group name")
    owner_first_name = models.CharField(max_length=20, blank=False, null=False)
    owner_last_name = models.CharField(max_length=20, blank=False, null=False)
    address = models.CharField(max_length=100, blank=False, null=False)
    phone = models.CharField(max_length=15, blank=False, null=False)
    billing_info = models.CharField(max_length=200, blank=False, null=False)
    uuid = models.UUIDField(unique=True, default=uuid.uuid4,
                            editable=False, blank=False, null=False)

    def __str__(self):
        return self.name
1
  • Can you share the migration for apps? It's likely it's missing the dependency on the migration that creates the table for the CustomerGroup model. Commented Jan 25, 2022 at 15:21

1 Answer 1

1

The issue was apparently caused by a view that get some default values from the database. The problem is there are no values yet as the database is empty.

The problem was solved by first commenting the urls so that django does not check the views during migration. Then migrate the database and run the server. I then added the default values that django looks for and uncomment the urls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.