Opened 15 years ago

Closed 15 years ago

#11366 closed (invalid)

mysql table name changed after command, 'python manage.py inspectdb > mysite/myapp/models.py'

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: no UI/UX: no

Description

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 models.py using the command, python manage.py inspectdb > mysite/myapp/models.py. 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, e.g.to query, Users.objects.all() had to be changed to myapp.users.objects.all().

Change History (3)

comment:1 by Henrique C. Alves, 15 years ago

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 by macky123, 15 years ago

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 models.py 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 models.py file within the application, you simply type the shell command: python mysite/manage.py inspectdb > mysite/myapp/models.py. 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 by Russell Keith-Magee, 15 years ago

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