Django makemigrations can‘t have more than one auto-generated field.

Django在创建模型时会默认生成主键字段,但允许开发者选择覆盖这一行为,例如通过定义一个带有`primary_key=True`的`BigAutoField`,如`id=models.BigAutoField(db_column=ID,unique=True,primary_key=True)`,这使得可以控制主键的特性和表现。

需要注意的是, django在设计模型时,会自动生成一个主键字段,如果你不想使用它自动生成的字段, 你可以自己定义一个自己的主键,而不是使用自动生成的字段。

出错前:id = models.BigAutoField(db_column='ID', unique=True) 

更改为:id = models.BigAutoField(db_column='ID', unique=True, primary_key=True

(venv) C:\Users\lenovo\PycharmProjects\gaitTest>python manage.py check --deploy SystemCheckError: System check identified some issues: ERRORS: admin.LogEntry.user: (fields.E300) Field defines a relation with model 'app.Doctor', which is either not installed, or is abstract. WARNINGS: ?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems. ?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS. ?: (security.W009) Your SECRET_KEY has less than 50 characters, less than 5 unique characters, or it's prefixed with 'django-insecure-' indicating that it was generated automatically by Django. Please generate a long and random value, otherwise many of Django's security-critical features will be vulnerable to attack. ?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions. ?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF t oken. ?: (security.W018) You should not have DEBUG set to True in deployment. System check identified 7 issues (0 silenced).
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值