diff --git a/backend/geonature/core/gn_monitoring/models.py b/backend/geonature/core/gn_monitoring/models.py index 80c14b9ac9..3536985003 100644 --- a/backend/geonature/core/gn_monitoring/models.py +++ b/backend/geonature/core/gn_monitoring/models.py @@ -246,7 +246,7 @@ class TObservations(DB.Model): digitiser = DB.relationship( User, primaryjoin=(User.id_role == id_digitiser), foreign_keys=[id_digitiser] ) - cd_nom = DB.Column(DB.Integer) + cd_nom = DB.Column(DB.Integer, DB.ForeignKey("taxonomie.taxref.cd_nom")) comments = DB.Column(DB.String) uuid_observation = DB.Column(UUID(as_uuid=True), default=select(func.uuid_generate_v4())) diff --git a/backend/geonature/migrations/versions/5b61bcaa18da_monitoring_add_cd_nom_foreign_key.py b/backend/geonature/migrations/versions/5b61bcaa18da_monitoring_add_cd_nom_foreign_key.py new file mode 100644 index 0000000000..35164b8d34 --- /dev/null +++ b/backend/geonature/migrations/versions/5b61bcaa18da_monitoring_add_cd_nom_foreign_key.py @@ -0,0 +1,40 @@ +"""[monitoring] Add cd_nom foreign key + +Revision ID: 5b61bcaa18da +Revises: 2894b3c03c66 +Create Date: 2025-01-07 14:28:20.475116 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "5b61bcaa18da" +down_revision = "2894b3c03c66" +branch_labels = None +depends_on = None + + +def upgrade(): + # Création clé étrangère sur la table t_observations + op.create_foreign_key( + "fk_t_observations_cd_nom_fkey", + source_schema="gn_monitoring", + source_table="t_observations", + local_cols=["cd_nom"], + referent_schema="taxonomie", + referent_table="taxref", + remote_cols=["cd_nom"], + onupdate=None, + ondelete=None, + ) + + +def downgrade(): + op.drop_constraint( + "fk_t_observations_cd_nom_fkey", + table_name="t_observations", + schema="gn_monitoring", + )