Django 4.0.4 Migration in a project upgrade, new fields not created in the DB

Hello,

I’m using Django 4.0.4, I have an association project that is currently running in V1 production.

I’ve made a lot of changes to this project and we now want to put V2 into production.

I’ve installed my V2 version on a new server, and I’ve retrieved a dump of the production postgresql DB.

Once everything is set up, I run the django migration commands.

python3 manage.py makemigrations …
python3 manage.py migrate

The problem is that it doesn’t create the new columns in my DB. I’ve searched the internet but can’t figure out why or how to solve it…

Thanks :slight_smile:

Here is a small example.


operations = [
        migrations.CreateModel(
            name='Test',
            fields=[
                ...
               # this new field appears in the migration but will never be set in the DB
                ('image', models.TextField(verbose_name='imagelink')),
            ],
        ),
            options={
                'permissions': (),
            },
        ),
    ]


Please post the output of a manage.py showmigrations command along with a directory listing of the migrations directory of that project.

Hello @KenWhitesell and thank you for your answer,

Here the output of the manage.py showmigrations
All apps are at initial state because i do the migrate zero command (on an advice on internet but didn’t solve my issue.)


admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
configurations
 [X] 0001_initial
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
events
 [X] 0001_initial
finances
 [X] 0001_initial
modules
 [X] 0001_initial
sales
 [X] 0001_initial
sessions
 [X] 0001_initial
shops
 [X] 0001_initial
static_precompiler
 [X] 0001_initial
stocks
 [X] 0001_initial
users
 [X] 0001_initial

I have not understand which migrations directory you need, I have one folder per app but not a global one.

.
├── borgia
├── configurations
├── events
├── finances
├── manage.py
├── modules
├── sales
├── shops
├── static
├── stocks
├── templates
└── users

Thanks again

It would be whichever app has the migrations that aren’t working.

Here the tree of the migration folder of shops (where image field and product_image is never created)

.
├── 0001_initial.py
├── __init__.py
└── __pycache__
    ├── 0001_initial.cpython-38.pyc
    └── __init__.cpython-38.pyc

1 directory, 4 files

Here the 0001_initial.py migration file


# Generated by Django 4.0.4 on 2023-07-24 13:33

from decimal import Decimal
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Shop',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255, validators=[django.core.validators.RegexValidator(message='Ne doit contenir que des lettres\n                                minuscules, sans espace ni caractère\n                                spécial.', regex='^[a-z]+$')], verbose_name='Code')),
                ('description', models.TextField(verbose_name='Description')),
                ('color', models.CharField(max_length=255, validators=[django.core.validators.RegexValidator(message='Doit être dans le format #F4FA58', regex='^#[A-Za-z0-9]{6}')], verbose_name='Couleur')),
                ('correcting_factor_activated', models.BooleanField(default=True, verbose_name='Activation du facteur de correction')),
                ('image', models.TextField(verbose_name='imagelink')),
            ],
        ),
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255, verbose_name='Nom')),
                ('unit', models.CharField(blank=True, choices=[('CL', 'cl'), ('G', 'g')], max_length=255, null=True, verbose_name='Unité')),
                ('is_manual', models.BooleanField(default=False, verbose_name='Gestion manuelle du prix')),
                ('manual_price', models.DecimalField(decimal_places=2, default=0, max_digits=9, validators=[django.core.validators.MinValueValidator(Decimal('0'))], verbose_name='Prix manuel')),
                ('correcting_factor', models.DecimalField(decimal_places=4, default=1, max_digits=9, validators=[django.core.validators.MinValueValidator(Decimal('0'))], verbose_name='Facteur correcteur de ventes')),
                ('is_active', models.BooleanField(default=True, verbose_name='Actif')),
                ('is_removed', models.BooleanField(default=False, verbose_name='Retiré')),
                ('product_image', models.CharField(max_length=10000, verbose_name='Image')),
                ('shop', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='shops.shop')),
            ],
            options={
                'permissions': (('change_price_product', 'Can change price of a product'),),
            },
        ),
    ]



Ok, and you’re saying that the migration you defined above at Django 4.0.4 Migration in a project upgrade, new fields not created in the DB is then 0002_whatever?

At the moment I only have one migration 0001_initial.py.

My Postgresql shop table has all the other columns because this is a previous SQL import.

So this migration must create 1 column in the shop table column: image.