postgres key is not present in table constraint

The error message simply states that there is at least one row in the table product_template that contains the value 12 in the column product_brand_id

But there is no corresponding row in the table product_brand where the column id contains the value 12

Key (product_brand_id)=(12) relates the source column of the foreign key, not the target column.


In simple terms, the value of FOREIGN KEY(product_brand_id) provided in your ALTER statement is not present in the source (product_brand) table.