Tuesday, April 4, 2023

Re: Migration running in shell, but no change in DB

What specifically was the changeset occurring and what isn't?  Is the model being created in the db, or is it the field change that's not replicating?  In your comments, you showed just one migration, but seems from additional comments you made, there are two or more?  What are they, specifically.  And what is the model field change you're making?

As mentioned earlier,  django model field changes do not always equate to a migration for that model.  So django made a migration for your model, but might also be an empty/no op one for your field change
On Tuesday, April 4, 2023 at 2:53:22 AM UTC-4 Martin Heitmann wrote:
Would you recommend using inspectdb?

On Monday, April 3, 2023 at 1:58:55 PM UTC+2 Martin Heitmann wrote:
Dear Jason

What could I do to get it back in sync? I tried several recommendations from the web, but perhaps the devil is in the details. If someone could tell me which steps I should take, I would gladly roll back the migrations and sync it again. And I would like to share the output. However, I have the existing database and may not loose the existing content.

As it seems to me I wanted to change a field more than a year ago. Perhaps that did not work. I do not remember. And now I wanted to add a new model to the app.

Best regards
Martin

On Monday, April 3, 2023 at 12:59:50 PM UTC+2 Jason wrote:
this is all a pretty weird experience, I have to say.  One thing that is suggesting to me that your migration history is.out of sync is that migration you shared earlier is not what I would expect an addField operation, not a CreateModel. 

Also, django migrations are required when model changes, but not all model changes require emitting SQL.  What exactly is the change you're expecting to see? What field, what was it before, and what do you want it to go to? 

On Sunday, April 2, 2023 at 3:43:27 PM UTC-4 Martin Heitmann wrote:
A little PS: I logged in via phpmyadmin and saw that my user has all privileges. So this should not be the source of the problem.

On Saturday, April 1, 2023 at 8:07:57 PM UTC+2 Martin Heitmann wrote:
I have a little update, but not a solution. Adding the database to sqlmigrate will give me the SQL command, but nothing more:

python3 manage.py sqlmigrate ObjPLW2 0037 --database=db_obj_plw2

--
-- Create model Wartungsarbeit
--
CREATE TABLE `ObjPLW2_wartungsarbeit` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `wa_titel` varchar(201) NOT NULL, `wa_beschreibung` longtext NOT NULL, `wa_turnus` integer UNSIGNED NOT NULL CHECK (`wa_turnus` >= 0), `wa_startdatum` date NOT NULL, `wa_erstelldatum` datetime(6) NOT NULL, `wa_bearbeitungsdatum` datetime(6) NOT NULL);

--
-- Alter field w_bezahlt on waeschepaket
--

And for whatever reason it includes only the table creation and not the change in the other field.
On Saturday, April 1, 2023 at 7:46:51 PM UTC+2 Martin Heitmann wrote:
Dear Jason

I went two migration steps back, then again I did makemigrations and then I went for sqlmigrate. This was the output:
python3 manage.py sqlmigrate ObjPLW2 0037
--
-- Create model Wartungsarbeit
--
--
-- Alter field w_bezahlt on waeschepaket
--
It does not include any SQL.

Does anyone know where this is no SQL in the output?

On Saturday, April 1, 2023 at 3:46:41 PM UTC+2 Martin Heitmann wrote:
Dear Jason
Thanks for your reply. I will gladly do that. This is the latest migration file:

# Generated by Django 3.2.10 on 2023-04-01 13:45

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        ('ObjPLW2', '0037_alter_waeschepaket_w_bezahlt'),
    ]

    operations = [
        migrations.CreateModel(
            name='Wartungsarbeit',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('wa_titel', models.CharField(max_length=201)),
                ('wa_beschreibung', models.TextField()),
                ('wa_turnus', models.PositiveIntegerField(default=1)),
                ('wa_startdatum', models.DateField(default=django.utils.timezone.now)),
                ('wa_erstelldatum', models.DateTimeField(auto_now_add=True)),
                ('wa_bearbeitungsdatum', models.DateTimeField(auto_now=True)),
            ],
        ),
    ]

Does this help?
On Saturday, April 1, 2023 at 1:55:00 PM UTC+2 Jason wrote:
part of getting effective help is sharing how you're doing things and the code.  for example, sharing the migration generated would be helpful. you do have the context of how and what is being executed, we don't, so sharing that with your original questions is a big part in getting effective help
On Saturday, April 1, 2023 at 4:08:06 AM UTC-4 Martin Heitmann wrote:
The migrations do not show up in the django_mirations table. The problem must occur earlier.
On Saturday, April 1, 2023 at 8:42:20 AM UTC+2 David Nugent wrote:
I would check in the django_migrations table to ensure that the migration has successfully been run.



From: 'Martin Heitmann' via Django users <django...@googlegroups.com>
Reply: django...@googlegroups.com <django...@googlegroups.com>
Date: 31 March 2023 at 19:46:02
To: Django users <django...@googlegroups.com>
Subject:  Migration running in shell, but no change in DB

Hello everyone

I have a project with multiple apps in it. As database I use MariaDB. Have not touched it for a while, but now I had to add a field to the models of one app. makemigrations and migrate run without any indication of an error. But no change occurs in the db. Tested it with an altered models.py in another app and the result is the same. Do you have any advice how to narrow this down?

Best regards
Martin
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/be9ef414-4b51-4072-a1b7-b7ba036016aan%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8b38e2b8-4afd-477a-9e89-893ebbc94e81n%40googlegroups.com.

No comments:

Post a Comment