Opened 7 years ago

Closed 7 years ago

#11366 closed (invalid)

mysql table name changed after command, 'python inspectdb > mysite/myapp/'

Reported by: macky123 Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I'm new to Django and deploying my app using the mysql database engine. Using Webmin, I added a new table to my database, and then successfully added it to using the command, python inspectdb > mysite/myapp/ However, one of my tables, the 'Users' table I had previously created, was somehow to 'myapp_users'. As a result, I have to change all my views that refer to this table, query, Users.objects.all() had to be changed to myapp.users.objects.all().

Change History (3)

comment:1 Changed 7 years ago by Henrique C. Alves

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: invalid
Status: newclosed

Django create table names as 'appname_modelname' to avoid name clashing, inspectdb doesn't rename any tables, and using myapp.Users instead of Users suggests that you're just importing names wrong on your view. I suggest following the tutorial and reading the documentation to understand better how Python and Django works.

comment:2 Changed 7 years ago by macky123

Resolution: invalid
Status: closedreopened

Thanks for your reply. But note that I'm using a legacy database and one of my tables had been named Users weeks ago, and somehow that name was changed. In other words, I had everything set up correctly in my views, and I suddenly got this error message that the table Users did not exist, and after searching through I discovered a name change to this table and model class, from Users to myapp.users. I'm following the tutorials and 'The Definitive Guide to django' very closely, since I'm new to web programming and don't know what I'm doing, and perhaps I did make a mistake, but I find that unlikely in this case. In Chapter 16 of that book, it discusses all this, and it all seems pretty straightforward. inspectdb examines the tables in the database and prints the generated model class for each table. To save the output to the file within the application, you simply type the shell command: python mysite/ inspectdb > mysite/myapp/ Somehow, the name of my table got changed when, from the shell, after I typed this command. A bug perhaps? I'm using the development version of Django. Again, thanks for replying, and perhaps I made some mistake.

comment:3 Changed 7 years ago by Russell Keith-Magee

Resolution: invalid
Status: reopenedclosed

If you've got a "how do I do this", or "am I doing anything wrong" question, you should be asking on the django-users mailing list. The ticket system is for logging known, understood and reproducible bugs.

Note: See TracTickets for help on using tickets.
Back to Top