这个指令应该是测试人员一定会使用的了,inspectdb,但关键在于,咱可能并非只是链接一个数据库,需要指定数据库。
python manage.py inspectdb --database [settings中数据库配置的key] > models具体路径
另外,django自动生成的注释,其实也很重要
# This is an auto-generated Django model module. # You'll have to do the following manually to clean this up: # * Rearrange models' order # * Make sure each model has one field with primary_key=True # * Make sure each ForeignKey and oneToOneField has `on_delete` set to the desired behavior # * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table # Feel free to rename the models, but don't rename db_table values or field names.
总结如下:
- 自行对models进行排序,因为python自己的机制,写在下面的类,上面的类是无法使用的
- 外键和一对一的关联关系,得自行构建
- managed=False标识这些models不是django迁移创建的
- 需要检查每一个model的主键,django不保证主键正确创建



