Open simensol opened 1 day ago
Thanks for reporting, definitely seems like a bug on pgtrigger's end. I will mark it as such and keep this open.
Are you able to currently work around this? The unfortunate hack right now may simply be manually removing the statement inserted into the initial migration file that installs the trigger.
I know that I've been able to successfully revert migrations in the past that drop tables with triggers, but I remember django doing some unexpected things with the ordering of some of these operations if they are in the same migration file.
Can you confirm that you have the creation of the model and the addition of a trigger in the same migration file?
If so, can you try marking atomic=False
in the migration file and reverting? This would at least give me more data that this is not a transaction-related issue.
Will see if I can reproduce this myself
The makemigrations
command generates two migration files for the app: 0001_initial.py
, which creates the model, and 0002_initial.py
, which creates constraints, triggers, ForeignKey
fields, and ManyToManyField
fields. The 0001_initial.py
file is listed as a dependency for 0002_initial.py
.
0001_initial.py
:
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Group',
fields=[
...
],
bases=(..., models.Model),
),
]
0002_initial.py
:
class Migration(migrations.Migration):
initial = True
dependencies = [
('groups', '0001_initial'),
...
]
operations are:
migrations.AddField(...),
migrations.AddField(...),
migrations.AddField(...),
migrations.AddConstraint(...),
migrations.AddConstraint(...),
pgtrigger.migrations.AddTrigger(
model_name='group',
trigger=pgtrigger.compiler.Trigger(name='RO_Group', sql=pgtrigger.compiler.UpsertTriggerSql(condition='WHEN (OLD."feide_id" IS DISTINCT FROM (NEW."feide_id") OR OLD."id" IS DISTINCT FROM (NEW."id") OR OLD."owner_id" IS DISTINCT FROM (NEW."owner_id"))', func="RAISE EXCEPTION 'pgtrigger: Cannot update rows from % table', TG_TABLE_NAME;", hash='130432f1fd9dcd2b84df3d5a24b09232b3276253', operation='UPDATE', pgid='pgtrigger_ro_group_deb1a', table='groups_group', when='BEFORE')),
),
]
Adding atomic = False
below initial = True
in both migration files does not make any difference. The same ProgrammingError
is raised.
I have not found a solution other than removing the trigger from the model's Meta
.
I am encountering a
ProgrammingError
when unapplying migrations that include triggers. The error occurs when running thepython manage.py migrate [app] zero
command or unapplying specific migrations. The issue seems to be related to the pgtrigger library attempting to install triggers on tables that have already been dropped.Here is an excerpt from one of the migration files generated by Django and
django-pgtrigger
:Here is relevant parts of the
Group
model:Here is the traceback of the error:
This may be related to #29, but I'm not sure.