as the title says there is a problem that I cannot resolve and that is that when I'm making migrations of my admin_db app it's just ignoring all the fields even though there are no commas etc and syntax is pretty much clean well I'm pasting my code.. any help would be really appreciated. P.S I'm using MYSQL as my database This is my admin model which I want to migrate
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)
corresponding migrations 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')),
],
),
]
As clearly seen there is not even a single field migrated from my models.py PLEASE HELP Thank you
CodePudding user response:
The <field_name>: <type>
syntax being used in your Admin
class is called type annotation and it doesn't set the actual attributes, so to set the actual attributes use =
instead of :
like in your other classes.
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)
...
Note that snake_case is the preferred way to case attributes in a class.