我正在使用Django版本1.8.3和mysql版本5.6.21 MySQL社区服务器(GPL)。
我一直在尝试为用户登录实现数据库,如下所示。
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
但当我对此manage.py migrate
时,我得到了
BEGIN;
ALTER TABLE `login_user` ALTER COLUMN `is_active` SET DEFAULT 1;
ALTER TABLE `login_user` ALTER COLUMN `is_active` DROP DEFAULT;
ALTER TABLE `login_user` ALTER COLUMN `is_admin` SET DEFAULT 0;
ALTER TABLE `login_user` ALTER COLUMN `is_admin` DROP DEFAULT;
COMMIT;
我不明白为什么它设置默认值然后丢弃它。 谁能告诉我这里发生了什么?
谢谢。
编辑:我添加了迁移文件。
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('first_name', models.CharField(max_length=50)),
('last_name', models.CharField(max_length=50)),
('email', models.EmailField(max_length=50)),
('password', models.CharField(max_length=50)),
('is_active', models.BooleanField()),
('is_admin', models.BooleanField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('num_friends', models.PositiveSmallIntegerField()),
('bio', models.CharField(max_length=150)),
('my_photo', models.ImageField(upload_to=b'profile')),
],
options={
},
bases=(models.Model,),
),
]
class Migration(migrations.Migration):
dependencies = [
('login', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='user',
name='is_active',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='user',
name='is_admin',
field=models.BooleanField(default=False),
),
]
mysql> desc login_user;
+-------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| first_name | varchar(50) | NO | | NULL | |
| last_name | varchar(50) | NO | | NULL | |
| email | varchar(50) | NO | | NULL | |
| password | varchar(50) | NO | | NULL | |
| is_active | tinyint(1) | NO | | NULL | |
| is_admin | tinyint(1) | NO | | NULL | |
| created_at | datetime(6) | NO | | NULL | |
| num_friends | smallint(5) unsigned | NO | | NULL | |
| bio | varchar(150) | NO | | NULL | |
| my_photo | varchar(100) | NO | | NULL | |
+-------------+----------------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)