260
Your models do not have primary keys. But they are being created automatically by django.
You need to choose type of auto-created primary keys
https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys (new in Django 3.2)
Either add this into settings.py
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
or
class Topic(models.Model):
id = models.AutoField(primary_key=True)
...
67
You have unintentionaly updated Django to 3.2 which warns you and as hint text suggest you have to set DEFAULT_AUTO_FIELD
as documented
This way you avoid unwanted migrations in future releases as
value of DEFAULT_AUTO_FIELD
will be changed to BigAutoField
You should set DEFAULT_AUTO_FIELD
explicitly to current DEFAULT_AUTO_FIELD
value
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
you could configure it even per app basis ( if you expect to build new apps with current style primary key)
from django.apps import AppConfig class MyAppConfig(AppConfig): default_auto_field = 'django.db.models.AutoField' name = 'my_app'
or even per-model (discouraged)
from django.db import models class MyModel(models.Model): id = models.AutoField(primary_key=True)
You should also take care of version locking your requirements as you could introduce backward incompatible changes in production
- [Django]-How to debug in Django, the good way?
- [Django]-How to save pillow image object to Django ImageField?
- [Django]-Django – accessing the RequestContext from within a custom filter
25
new created project settings.py
file in django 3.2
includes this:
..
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
and as your project was created on earlier versions of django so you can append this to your settings.
- [Django]-Difference between User.objects.create_user() vs User.objects.create() vs User().save() in django
- [Django]-A field with precision 10, scale 2 must round to an absolute value less than 10^8
- [Django]-How to access a dictionary element in a Django template?
6
models.py:
class Topic(models.Model):
id = models.AutoField(primary_key=True)
primary_key=True
https://docs.djangoproject.com/en/3.2/ref/models/fields/#primary-key
settings.py:
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_AUTO_FIELD
https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
- [Django]-Paginating the results of a Django forms POST request
- [Django]-Github issues api 401, why? (django)
- [Django]-How to iterate through dictionary in a dictionary in django template?
1
A simple solution:
Django wants you to add the serial number that’s called by primary key and if you can ignore this warning then okay django will automatically add the primary key otherwise, if you want to remove this warning then add this code in your defined model:
id = models.AutoField(primary_key=True)
For example:
class Contact(models.Model):
sno = models.AutoField(primary_key=True)
name = models.CharField(max_length=25, blank=True)
email = models.EmailField(max_length=40, blank=True)
phone = models.IntegerField()
HaPpY Coding
- [Django]-Django – makemigrations – No changes detected
- [Django]-How to run own daemon processes with Django?
- [Django]-Extend base.html problem