1
0
forked from ScoDoc/ScoDoc

Add cascade, fixing excpetion on semset delete

This commit is contained in:
Emmanuel Viennet 2021-09-10 21:48:04 +02:00
parent 8589aab659
commit 6074cc3892
2 changed files with 43 additions and 2 deletions

View File

@ -325,10 +325,15 @@ class NotesSemSet(db.Model):
sem_id = db.Column(db.Integer, nullable=True, default=None) sem_id = db.Column(db.Integer, nullable=True, default=None)
# Association: # Association: many to many
notes_semset_formsemestre = db.Table( notes_semset_formsemestre = db.Table(
"notes_semset_formsemestre", "notes_semset_formsemestre",
db.Column("formsemestre_id", db.Integer, db.ForeignKey("notes_formsemestre.id")), db.Column("formsemestre_id", db.Integer, db.ForeignKey("notes_formsemestre.id")),
db.Column("semset_id", db.Integer, db.ForeignKey("notes_semset.id")), db.Column(
"semset_id",
db.Integer,
db.ForeignKey("notes_semset.id", ondelete="CASCADE"),
nullable=False,
),
db.UniqueConstraint("formsemestre_id", "semset_id"), db.UniqueConstraint("formsemestre_id", "semset_id"),
) )

View File

@ -0,0 +1,36 @@
"""ScoDoc 9.0.13: essai cascade
Revision ID: a217bf588f4c
Revises: f73251d1d825
Create Date: 2021-09-10 21:44:34.947317
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a217bf588f4c'
down_revision = 'f73251d1d825'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('notes_semset_formsemestre', 'semset_id',
existing_type=sa.INTEGER(),
nullable=False)
op.drop_constraint('notes_semset_formsemestre_semset_id_fkey', 'notes_semset_formsemestre', type_='foreignkey')
op.create_foreign_key(None, 'notes_semset_formsemestre', 'notes_semset', ['semset_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'notes_semset_formsemestre', type_='foreignkey')
op.create_foreign_key('notes_semset_formsemestre_semset_id_fkey', 'notes_semset_formsemestre', 'notes_semset', ['semset_id'], ['id'])
op.alter_column('notes_semset_formsemestre', 'semset_id',
existing_type=sa.INTEGER(),
nullable=True)
# ### end Alembic commands ###