Introduction
This is an article where the main concern is to be able to focus on how to solve a warning message. Precisely, the warning message appear upon the execution of the command for starting an internal Django-based application server. The following is the execution of that command :
C:\python\django\project\project\office\models.py changed, reloading. Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). January 07, 2022 - 08:39:11 Django version 3.2.6, using settings 'core.settings' Starting development server at http://127.0.0.1:5000/ Quit the server with CTRL-BREAK. myapp.Employee: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
And below is the content of the ‘models.py’ file where the model which is becoming the target for the warning message :
class Employee(models.Model): name = models.CharField(max_length=50) class Meta: verbose_name_plural = "Employee" def __str__(self): return self.name
There are many more of it, but the above is just one simple example for demonstration.
Solution
This is part is the solution part for solving the warning message appear upon the execution of the Django-based application internal server. The solution is very easy. Just add the following line into every model available. In this context, the term for every available model only for those models which become the part of the application. There is a parameter in the ‘settings.py’ file with the name of ‘INSTALLED_APPS’. Actually, the warning message for the model, it is the model where the application is being registered in that INSTALLED_APPS parameter. The following is the example of it :
# Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'apps.home', # Enable the inner home (home) 'myapp' ]
So, the model ‘Employee’ must be a part of either one of the app definition. But definitely it is ‘myapp’ since the ‘Employee’ model is a user definition. The following is the additional line to handle the warning messaage :
id = models.AutoField(primary_key=True)
So, the following is the modification of the models.py file by adding the above line :
class Employee(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=50) class Meta: verbose_name_plural = "Employee" def __str__(self): return self.name