reporting module liquibase error

Just built the reporting module from master and tried installing it but I’m getting liquibase errors.

This changeset

<changeSet id="reporting_report_design_6" author="mseaton">
	<preConditions onFail="MARK_RAN">
		<columnExists tableName="reporting_report_design" columnName="report_definition_id"/>
	</preConditions>
	<comment>
		Step 4 in changing reporting_report_design to reference report definition
		by uuid rather than id, in order to not tie it directly to the serialized object table
		Drop report_definition_id column
	</comment>
	<dropColumn tableName="reporting_report_design" columnName="report_definition_id" />
</changeSet>

fails with error

Caused by: liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE `reporting_report_design` DROP COLUMN `report_definition_id`: Cannot drop index 'report_definition_id for reporting_report_design': needed in a foreign key constraint
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62)
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104)
	at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1091)
	at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1075)
	at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
	... 7 more
Caused by: java.sql.SQLException: Cannot drop index 'report_definition_id for reporting_report_design': needed in a foreign key constraint
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2768)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:949)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:795)
	at liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)

The changeset is trying to delete a column which has a foreign key constraint. The constraint was supposed to be removed with

<changeSet id="reporting_report_design_4" author="mseaton">
<validCheckSum>3:bddba97d81d6daa7fd6fbb478897fd84</validCheckSum> <!-- old checksum without clean constraint names -->
<validCheckSum>3:e557ea83775089ed9e636768b25de9a0</validCheckSum> <!-- current checksum with clean constraint names -->
	<preConditions onFail="MARK_RAN">
		<or>
			<and>
				<dbms type="mysql" />
				<sqlCheck expectedResult="1">
					SELECT  count(*)
					FROM    INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
					WHERE   KCU.TABLE_SCHEMA = database()
					AND     KCU.TABLE_NAME = 'reporting_report_design'
					AND     KCU.CONSTRAINT_NAME = 'report_definition_id_for_reporting_report_design'
				</sqlCheck>
			</and>
			<and>
				<not>
					<dbms type="mysql" />
				</not>
				<foreignKeyConstraintExists foreignKeyName="report_definition_id_for_reporting_report_design"/>
			</and>
		</or>
	</preConditions>
	<dropForeignKeyConstraint baseTableName="reporting_report_design" constraintName="report_definition_id_for_reporting_report_design" />
</changeSet>

But wasn’t because both preconditions fail.

SELECT  count(*)
FROM    INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
WHERE   KCU.TABLE_SCHEMA = database()
AND     KCU.TABLE_NAME = 'reporting_report_design'
AND     KCU.CONSTRAINT_NAME = 'report_definition_id_for_reporting_report_design'

returns 0 instead of 1 as expected by the sqlCheck

Did you figure this out?

@dkayiwa I woke up the next day and the error was gone.

Woowww! I like that style of solving problems. :smile:

@dkayiwa

Apparently this was not a good way to fix things. The error came back after I made a changed unrelated to the db and I rebuilt and deployed, now reporting module won’t start with the same error as described above and not even a restart works now.

Which OpenMRS platform version are you running?

OpenMRS 1.9.11

Do you get the same problem with a released (non snapshot) version of the module?