Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading