The first field in the models.py not created, how to fix it? (django)

I have written two classes in models.py (Django):

class Name_tickers(models.Model):
    ticker = models.CharField(max_length = 32)
    name = models.CharField(max_length = 100)

    def __str__(self):
        return self.ticker


class Close_stock(models.Model):
        date = models.DateField(),
        tiker_name = models.ForeignKey(Name_tickers, on_delete=models.CASCADE),
        price = models.DecimalField(max_digits=15, decimal_places=5)

But was created:

migrations.CreateModel(
            name='Close_stock',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('price', models.DecimalField(decimal_places=5, max_digits=15)),
            ],
        ),
        migrations.CreateModel(
            name='Name_tickers',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('ticker', models.CharField(max_length=32)),
                ('name', models.CharField(max_length=100)),
            ],
        ),

How to fix it and add my first fields?

I tried to delete migrations and create them again – it doesn’t work

>Solution :

You need to remove trailing commas from class:

class Close_stock(models.Model):
        date = models.DateField(), <-- here
        tiker_name = models.ForeignKey(Name_tickers, on_delete=models.CASCADE), <-- and here
        price = models.DecimalField(max_digits=15, decimal_places=5)

Leave a Reply