makemigrations 忽略所有字段(DJANGO)

makemigrations ignoring all the fields (DJANGO)

正如标题所说,有一个我无法解决的问题,那就是当我迁移我的 admin_db 应用程序时,它只是忽略了所有字段,即使没有逗号等和语法非常干净,我正在粘贴我的代码.. 任何帮助将不胜感激。 P.S 我正在使用 MYSQL 作为我的数据库 这是我要迁移的管理模型

from django.db import models
from datetime import datetime


# Create your models here.
class Admin(models.Model):
    Admin_Email: models.EmailField(primary_key=True, editable=False)
    First_name: models.CharField(max_length=25)
    Last_name: models.CharField(max_length=25)
    Gender: models.CharField(max_length=1)
    Date_of_registration: models.DateField(default=datetime.now, editable=False)
    Date_of_Birth: models.DateField()
    CNIC: models.BigIntegerField(max_length=13, unique=True)
    City: models.CharField(max_length=50)
    Area: models.CharField(max_length=50)
    Address: models.CharField(max_length=100)
    Phone_num: models.BigIntegerField(max_length=11, unique=True)


class Salt(models.Model):
    Admin_email = models.OneToOneField(Admin, on_delete=models.CASCADE)
    Salt = models.CharField(max_length=25, unique=True)


class Password(models.Model):
    Admin_email = models.OneToOneField(Admin, on_delete=models.CASCADE)
    hash = models.CharField(max_length=255, unique=True)

对应的迁移0001_initial.py

# Generated by Django 3.2.8 on 2021-11-07 18:58

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Admin',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
        ),
        migrations.CreateModel(
            name='Salt',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Salt', models.CharField(max_length=25, unique=True)),
                ('Admin_email', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='admin_db.admin')),
            ],
        ),
        migrations.CreateModel(
            name='Password',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('hash', models.CharField(max_length=255, unique=True)),
                ('Admin_email', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='admin_db.admin')),
            ],
        ),
    ]

很明显,我的 models.py 甚至没有一个字段迁移过来 请帮忙 谢谢

Admin class 中使用的 <field_name>: <type> 语法称为 type annotation 并且它不设置实际属性,因此设置实际属性使用= 而不是像其他 class 那样的 :

class Admin(models.Model):
    admin_Email = models.EmailField(primary_key=True, editable=False)
    first_name = models.CharField(max_length=25)
    last_name = models.CharField(max_length=25)
    ...

请注意,snake_case 是 class 中大小写属性的首选方式。