Home > OS >  Python makemigrations does not work right
Python makemigrations does not work right

Time:11-18

I use Django framework

This is my models.py

from django.db import models

# Create your models here.


class Destination(models.Model):

    name: models.CharField(max_length=100)
    img: models.ImageField(upload_to='pics')
    desc: models.TextField
    price: models.IntegerField
    offer: models.BooleanField(default=False)

and here is my migrations folder-0001_initial.py:

# Generated by Django 4.1.3 on 2022-11-17 10:17

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Destination',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
        ),
    ]

it don't migrate my model, i deleted 0001_initial.py and pycache and migrate again but it worked the same

How can i make migrations with my models ?

CodePudding user response:

You have added model fields in incorrect way. You can't add like this.

change this:

class Destination(models.Model):
    name: models.CharField(max_length=100)
    img: models.ImageField(upload_to='pics')
    desc: models.TextField
    price: models.IntegerField
    offer: models.BooleanField(default=False)

To this:

class Destination(models.Model):
    name = models.CharField(max_length=100)
    img = models.ImageField(upload_to='pics')
    desc = models.TextField()
    price = models.IntegerField()
    offer = models.BooleanField(default=False)

After changing above code. Try to migrate manually using below command:

python manage.py makemigrations appname

python manage.py sqlmigrate appname 0001 #This value will generate after makemigrations. it can be 0001 or 0002 or more

python manage.py migrate
  • Related