Error when reading SQL Server data from Django with a different database name

Asked 2 years ago, Updated 2 years ago, 97 views

Django is writing a program to read data from SQL Server, but an object that is different from the actual database name is generated, resulting in an error.
The contents of the error are as follows, but I don't know why 'app_usertable' is generated.
The raw method produces the same error.

('42S02', "[42S02] [Microsoft] [ODBC Driver 17 for SQL Server] [SQL Server]Invalid object name 'app_usertable'. (208) (SQLExecDirectW); Failed to prepare [42S02] [Microsoft] [ODBC Driver 17 for SQL Server] [SQL Server] statement. (8180)"

models.py

class UserTable(models.Model): 
    userid=models.CharField(max_length=32)
    username=models.CharField(max_length=32) 
   
    def__str__(self): 
        return self.name 
    

views.py

data=UserTable.objects.filter(userid='sato')

for x in data:
    print(x.userid)

Enter a description of the image here

python django sql-server

2022-09-30 18:12

1 Answers

Try building your model with manage.py inspectdb instead of documentation.
It will probably work.


2022-09-30 18:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.