django 中 如果没有 primary_key,是否无法建立 model?
老数据表,本身没有 primary_key 是不是必须要指定一个 primary_key ? 之前用过 peewee,可以设置无 primary_key 数据表
老数据表,本身没有 primary_key 是不是必须要指定一个 primary_key ? 之前用过 peewee,可以设置无 primary_key 数据表
https://kapeli.com/dash_share?docset_file=Django&docset_name=Django&path=doc/ref/models/fields.html%23s-primary-key&platform=django&repo=Main&version=3.1.4
## primary_key
Field.primary_key
If True, this field is the primary key for the model.
If you don’t specify primary_key=True for any field in your model, Django will automatically add an AutoField to hold the primary key, so you don’t need to set primary_key=True on any of your fields unless you want to override the default primary-key behavior. For more, see Automatic primary key fields.
primary_key=True implies null=False and unique=True. Only one primary key is allowed on an object.
The primary key field is read-only. If you change the value of the primary key on an existing object and then save it, a new object will be created alongside the old one.
我觉得应该有办法可以去做些处理,但我最近迷上 go 。
如果回头你还没解决办法,我可以来玩下。
你可以试下从这个角度去看看
python manage.py inspectdb
从 sql 反向成 model
简单还是 py 简单,而且很傻瓜式
但我不怎么想写 py 了,感觉太飘。