Upgraded database fails on import with `null value "acquisition_device_type" violates not-null constraint`
Prevents import of fluoro from RDSR - not sure about others. CT is fine.
Comments (24)
-
reporter -
Is that the database field that was never populated? If so, what happens if you manually delete the field?
-
reporter Manually deleting the field makes it work. I'm just hating the idea people need to do this.
-
reporter Instructions for deleting this field using the command line (tested with postgres):
cd path/to/openrem python manage.py dbshell
Enter password when prompted - you can find this in your
openrem/openremproject/local_settings.py
file.ALTER TABLE remapp_projectionxrayradiationdose DROP COLUMN acquisition_device_type; \q
-
reporter Alternatively you can do it with pgAdmin III, or phpmyadmin for MySQL etc
-
I haven't tried this, but what about a migration file that adds the field and then deletes it?
-
Hi Ed,
We can have a migration file that runs a line of SQL that deletes the field. I've tried this and it works when the field already exists in the database. If the field isn't there then it produces an error complaining that it does not exist.
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations from django.conf import settings from django.db.models.loading import get_model class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('remapp', '0001_initial'), ] operations = [ migrations.RunSQL("ALTER TABLE remapp_projectionxrayradiationdose DROP COLUMN acquisition_device_type;"), ]
-
reporter Thanks @dplatten. If you don't have the field, then you are left with an unapplied migration. This can be fixed with a subsequent
python manage.py migrate remapp --fake
.Question is, how do we distribute this file and the instructions. A new release? Along with the necessary instructions?
-
reporter psql has
DROP COLUMN [ IF EXISTS ]
which might avoid the error - I don't know at this stage if that is standard SQL -
reporter I think it is standard SQL, and if it is there then the migration can proceed successfully whether the column is there or not.
-
The following deletes the field if it's there, and also runs without error if there is no field there:
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations from django.conf import settings class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('remapp', '0003_delete_field_if_exists'), ] operations = [ migrations.RunSQL("ALTER TABLE remapp_projectionxrayradiationdose DROP COLUMN IF EXISTS acquisition_device_type;"), ]
-
I should say that the above is tested with PostgreSQL only.
-
reporter Adding new migration file for deleting field from 0.6 series databases. Refs
#415and copied from comment made by @dplatten on that issue.→ <<cset 684921a1618d>>
-
reporter Starting to populate the release notes fro 0.7.2 Refs
#415→ <<cset 3520798540a7>>
-
reporter showmigrations from 0.7.1 via 0.6. Committing to check formatting. Refs
#415→ <<cset f201f9f2f370>>
-
reporter Adding a link for release 0.7.2 docs so they are built. Refs
#415→ <<cset abfa25c5bcd2>>
-
reporter Basic instructions complete. Refs
#415→ <<cset 4e268d9d5b30>>
-
reporter Renaming migration file as per docs. Refs
#415→ <<cset e0481de7f5fa>>
-
reporter Added upgrade from 0.6 series note, and link to ref
#415→ <<cset c10640060a5d>>
-
reporter Merging ref
#415back into develop in preparation for beta release of 0.7.2→ <<cset baa0779a5f50>>
-
reporter Installed 0.7.2b1 on a server with postgresql and had been upgraded 0.6.x to 0.7.1. The command to
migrate remapp
resulted in the following error:CommandError: Conflicting migrations detected (0002_upgrade_0_7_from_0_6, 000x_delete_060_acq_field in remapp). To fix them run 'python manage.py makemigrations --merge'
Running the suggested command resulted in:
Merging remapp Branch 0002_upgrade_0_7_from_0_6 [0/2447] - Create model DicomDeleteSettings - Create model DicomQRRspImage - Create model DicomQRRspSeries - Create model DicomQRRspStudy - Create model DicomQuery - Create model DicomRemoteQR - Create model DicomStoreSCP - Create model PatientIDSettings - Create model UniqueEquipmentNames - Create model SkinDoseMapCalcSettings - Add field reference_point_definition_text to irradeventxraydata - Add field export_user to exports - Add field includes_pid to exports - Add field accession_hashed to generalstudymoduleattr - Add field acquisition_device_type_cid to projectionxrayradiationdose - Add field study_workload_chart_time to generalstudymoduleattr - Raw Python operation - Add field id_hashed to patientmoduleattr - Add field name_hashed to patientmoduleattr - Add field median_available to userprofile - Add field plotAverageChoice to userprofile - Add field plotCTInitialSortingChoice to userprofile - Add field plotCTRequestFreq to userprofile - Add field plotCTRequestMeanDLP to userprofile - Add field plotCTStudyMeanCTDI to userprofile - Add field plotDXAcquisitionMeankVpOverTime to userprofile - Add field plotDXAcquisitionMeanmAsOverTime to userprofile - Add field plotDXInitialSortingChoice to userprofile - Add field plotInitialSortingDirection to userprofile - Add field plotDXStudyMeanDAP to userprofile - Add field plotDXStudyFreq to userprofile - Add field plotDXRequestMeanDAP to userprofile - Add field plotDXRequestFreq to userprofile - Add field plotSeriesPerSystem to userprofile - Add field plotHistogramBins to userprofile - Alter field accession_number on generalstudymoduleattr - Alter unique_together for uniqueequipmentnames (1 constraint(s)) - Add field qr_scp_fk to dicomquery - Add field store_scp_fk to dicomquery - Add field dicom_query to dicomqrrspstudy - Add field dicom_qr_rsp_study to dicomqrrspseries - Add field dicom_qr_rsp_series to dicomqrrspimage - Add field unique_equipment_name to generalequipmentmoduleattr - Add field plotHistograms to userprofile - Add field plotMGAGDvsThickness to userprofile - Add field plotMGStudyPerDayAndHour to userprofile - Add field plotRFInitialSortingChoice to userprofile - Add field plotRFStudyDAP to userprofile - Add field plotRFStudyFreq to userprofile - Add field plotRFStudyPerDayAndHour to userprofile - Raw Python operation - Raw SQL operation Branch 000x_delete_060_acq_field - Raw SQL operation Merging will only work if the operations printed above do not conflict with each other (working on different fields or models) Do you want to merge these migration branches? [y/N]
Responding
y
to this created0003_merge.py
with ashowmigrations
looking like this:remapp [X] 0001_initial [ ] 000x_delete_060_acq_field [X] 0002_upgrade_0_7_from_0_6 [ ] 0003_merge
The merge migration file itself looked like this:
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('remapp', '0002_upgrade_0_7_from_0_6'), ('remapp', '000x_delete_060_acq_field'), ] operations = [ ]
The
migrate remapp
operation then ran successfully, leavingshowmigrations
looking like:remapp [X] 0001_initial [X] 000x_delete_060_acq_field [X] 0002_upgrade_0_7_from_0_6 [X] 0003_merge
-
reporter - changed milestone to 0.7.3
-
reporter - changed status to resolved
Fixed in 0.7.3 release
-
reporter Updated changes/CHANGES and release notes. Refs
#413,#415.#416→ <<cset 7aa3b9a42759>>
- Log in to comment
Refs
#399