【发布时间】:2020-08-18 14:16:42
【问题描述】:
我是 Django 的新手。我正在为我的 django 项目使用 Mysql 数据库。我在 models.py 中创建了模型类。
在我的models.py中
from django.db import models
class AuthModel(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.CharField(max_length=255)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
我已使用以下命令将此字段迁移到我的 Mysql 数据库中
Python manage.py makemigrations
Python manage.py migrate
现在,我想在表中再添加一列“user_type”。
我可以从数据库中手动添加“user_type”列,但它不会将“user_type”值插入表中。因为我的“AuthModel”中没有包含“user_type”列。
如果我将 user_type 包含到“AuthModel”中并运行迁移命令,但是它不起作用。我想将 user_type 列添加到我的表中。该怎么做?
【问题讨论】:
标签: python django django-models django-forms django-views