Reputation: 52
THIS IS MY MODEL FILE
from django.db import models
class Donor(models.Model):
Donor_name = models.CharField(max_length=150),
Donor_status = models.IntegerField(),
Donor_city = models.CharField(max_length=50),
Donor_group = models.CharField(max_length=10),
Donor_phone = models.CharField(max_length=12),
Donor_mail = models.EmailField(max_length=50)
THIS IS MY MIGRATION
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Donor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
)
Why are other fields ignored ? using Django version 2 with MySQL.
Upvotes: 1
Views: 1298
Reputation: 308799
The commas at the end of the lines cause Python to treat them as tuples. Remove them.
class Donor(models.Model):
Donor_name = models.CharField(max_length=150)
Donor_status = models.IntegerField()
Donor_city = models.CharField(max_length=50)
Donor_group = models.CharField(max_length=10)
Donor_phone = models.CharField(max_length=12)
Donor_mail = models.EmailField(max_length=50)
Once you have made this change, you can run makemigrations
again and Django should include your new fields. If you haven't run the migration that creates the modlel yet, you could remove the migration file before doing this. You can use python manage.py showmigrations
to check whether the migration has already been run.
Note that in Django, the recommendation is to use lowercase_with_underscores for your field names, e.g. donor_name
and donor_status
.
Upvotes: 4