Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django only adding one field from model

When I edit a model to have more fields, and make migrations, Django won't add a new field without removing the old one.

Here is the model

class Testimonial(models.Model):
    name = models.CharField(max_length=20, null=True),
    quote = models.CharField(max_length=255, null=True),
    test = models.CharField(max_length=20, null=True)

This is what I get in the terminal

Migrations for 'testimonials':
0004_auto_20160212_1537.py:
- Remove field quote from testimonial
- Add field test to testimonial

and this is the most recent migration

from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('testimonials', '0003_auto_20160212_1536'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='testimonial',
            name='quote',
        ),
        migrations.AddField(
            model_name='testimonial',
            name='test',
            field=models.CharField(max_length=20, null=True),
        ),
    ]
like image 592
TJB Avatar asked Apr 18 '26 09:04

TJB


1 Answers

I'm pretty sure the issue is caused by the commas you have for the trailing fields, in python, this is indicating that you're creating a tuple and it will treat the next line as a continuation of that tuple object, you need to remove them

class Testimonial(models.Model):
    name = models.CharField(max_length=20, null=True),
    quote = models.CharField(max_length=255, null=True),
    test = models.CharField(max_length=20, null=True)

should be

class Testimonial(models.Model):
    name = models.CharField(max_length=20, null=True)
    quote = models.CharField(max_length=255, null=True)
    test = models.CharField(max_length=20, null=True)
like image 107
Sayse Avatar answered Apr 19 '26 23:04

Sayse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!