Table names
To save you time, Django automatically derives the name of the database table from the name of your model class and the app that contains it. A model's database table name is constructed by joining the model's "app label" -- the name you used inmanage.py startapp-- to the model's class name, with an underscore between them.
For example, if you have an app bookstore (as created bymanage.pystartapp bookstore), a model defined asclass Book will have a database table namedbookstore_book.
To override the database table name, use the db_table parameter inclassMeta.
If your database table name is an SQL reserved word, or contains characters that aren't allowed in Python variable names -- notably, the hyphen -- that's OK. Django quotes column and table names behind the scenes.
为节省您的时间,Django自动重写了数据库表,包含你的model class和app名称。一个model's数据表命名是由app label构建的。使用manage.py startapp命令去创建model's class名称,并在他们之间加上下划线。
例如,如果你有一个app叫bookstore(就像是使用manage.py startapp bookstore命令创建一个app一样),还有一个model定义为class Book,那么这个数据表就叫做bookstore_book。
如果要重写这个数据表名称,在class Meta中使用db_table参数。
如果你的数据表名称是一个SQL的保留字,或者是包含一个在Python变量名中的字符是不被允许使用的,这里特别说明一下,连字符是可以的。因为Django引用列和表名称是在幕后进行的。