Django 장고
foreign key를 null=true로 했는데 Column 'form_id' cannot be null이 나온다(mac)
jennyiscoding
2024. 6. 26. 10:27
뽀린키 속성을 없앤다
Find the name of the foreign key constraint (you can see it in the error message or by looking up the table structure), and then drop it:
ALTER TABLE machine_report_attachment DROP FOREIGN KEY machine_report_attac_form_id_b4c038bd_fk_machine_r;
form_id속성을 다시 부여한다
Now, modify the column to be nullable as initially intended:
ALTER TABLE machine_report_attachment MODIFY form_id BIGINT NULL;
Step 3:뽀린키 속성을 다시 부여한다
If the relationship is still necessary, add the foreign key constraint back with the new settings. Ensure that the referenced primary key column (id in MachineReportForm) is compatible:
ALTER TABLE machine_report_attachment
ADD CONSTRAINT fk_machine_report_attachment_form_id
FOREIGN KEY (form_id) REFERENCES machine_report_form(id);