savoirfairelinux / sous-chef

Sous-Chef is a web application to help organizations to plan and deliver meals, and to manage clients files.
GNU Affero General Public License v3.0
66 stars 45 forks source link

Model changes "not yet reflected in a migration" #670

Closed lingxiaoyang closed 7 years ago

lingxiaoyang commented 7 years ago

Expected Behaviour

The migrations should always match models.py.

Actual Behaviour

A fresh installation of sous-chef gives the following warning:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
    HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.10/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, avatar, billing, contenttypes, delivery, meal, member, note, notification, order, sessions
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

And following makemigrations:

root@b9ba08fbb5e8:/code/src# python manage.py makemigrations
Migrations for 'note':
  note/migrations/0010_auto_20170221_1947.py:
    - Alter field category on note
    - Alter field priority on note
Migrations for 'meal':
  meal/migrations/0007_auto_20170221_1947.py:
    - Alter field component_group on component
Migrations for 'member':
  member/migrations/0026_auto_20170221_1947.py:
    - Alter field vehicle on route

It seems that sous-chef misses few migration files in the repo.

Steps to reproduce

lingxiaoyang commented 7 years ago

@manumilou There's a hint for enabling MySQL strict mode that "fixes many data integrity problems in MySQL". Do you think it's better to enable this, or don't worry about it?

lingxiaoyang commented 7 years ago

Investigation of what "not reflected model changes" are:

For meal:

Existing (meal.0005):
            field=models.CharField(choices=[('main_dish', 'Main Dish'), ('dessert', 'Dessert'), ('diabetic', 'Diabetic Dessert'), ('fruit_salad', 'Fruit Salad'), ('green_salad', 'Green Salad'), ('pudding', 'Pudding'), ('compote', 'Compote')], max_length=100, verbose_name='component group'),

To be changed to:
            field=models.CharField(choices=[('main_dish', 'Main Dish'), ('dessert', 'Dessert'), ('diabetic', 'Diabetic Dessert'), ('fruit_salad', 'Fruit Salad'), ('green_salad', 'Green Salad'), ('pudding', 'Pudding'), ('compote', 'Compote'), ('sides', 'Sides')], max_length=100, verbose_name='component group'),

For member:

Existing (member.0025):
            field=models.CharField(choices=[('cycling', 'Cycling'), ('walking', 'Walking'), ('driving', 'Driving')], default='cycling', max_length=20, verbose_name='default vehicle'),

To be changed to:
            field=models.CharField(choices=[('cycling', 'Cycling'), ('walking', 'Walking'), ('driving', 'Driving')], default='cycling', max_length=20, verbose_name='vehicle'),

For note:

Existing (note.0009):
        migrations.AlterField(
            model_name='note',
            name='category',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='note.NoteCategory', verbose_name='Category'),
        ),
        migrations.AlterField(
            model_name='note',
            name='priority',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='note.NotePriority', verbose_name='Priority'),
        ),

To be changed to:
        migrations.AlterField(
            model_name='note',
            name='category',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='note.NoteCategory', verbose_name='Category'),
        ),
        migrations.AlterField(
            model_name='note',
            name='priority',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='note.NotePriority', verbose_name='Priority'),
        ),