Django creates instances of data tables based on the data model models
- 2020-09-16 07:33:27
- OfStack
If you use the default database SQLite3, you do not need to configure ES2en.py
With other databases, you need to configure settings.py, for example, Mysql.
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'webapp',# The database name
'USER':'test1',# The user name
'PASSWORD':'123456',# password
'HOST':'127.0.0.1',
'PORT':'3306',
}
}
Complete the data model creation in ES12en.py:
class student(models.Model):
# class Meta:
# db_table = 'User_table'# Specifies the name of the data table
name = models.CharField(max_length=50)
sex = models.CharField(max_length=10)
birthday = models.DateField()
telephone = models.BigIntegerField()
def __str__(self):
return self.name
And complete the registration in ES17en.py:
from webapp import models
admin.site.register(models.student)
Finally, cd goes to the folder of manage.py and enters the following command
# Django 1.6.x And the following
python manage.py syncdb
# Django 1.7 Versions of and above require the following command
python manage.py makemigrations
python manage.py migrate
#python2.7 manage.py **** # If you have more than one python The version is best specified
If python ES29en.py migrate reports an error, try es32EN2.7 manage.py migrate appname --fake.
If not, check for errors and try again.