Deleting database fails with foreign key violation

[2ae8e69b-984c-44ad-b535-b4b4c1e4b285] 2021-04-08T17:05:02-06:00 ERROR metabase.driver.sql-jdbc.execute nil [2ae8e69b-984c-44ad-b535-b4b4c1e4b285] 2021-04-08T17:05:08-06:00 ERROR metabase.driver.sql-jdbc.execute nil [2ae8e69b-984c-44ad-b535-b4b4c1e4b285] 2021-04-08T17:05:08-06:00 ERROR metabase.middleware.log DELETE /api/database/4 500 56.5 ms (9 DB calls) {:message "ERROR: update or delete on table \"report_card\" violates foreign key constraint \"fk_card_label_ref_card_id\" on table \"card_label\"\n Detail: Key (id)=(23) is still referenced from table \"card_label\".", :type org.postgresql.util.PSQLException, :stacktrace ("org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2497)" "org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2233)" "org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:310)" "org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)" "org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)" "org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:149)" "org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:124)" "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:462)" "clojure.java.jdbc$db_do_execute_prepared_statement$fn__18810.invoke(jdbc.clj:1031)" "clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:799)" "clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:769)" "clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:782)" "clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:769)" "clojure.java.jdbc$db_do_execute_prepared_statement.invokeStatic(jdbc.clj:1030)" "clojure.java.jdbc$db_do_execute_prepared_statement.invoke(jdbc.clj:1024)" "clojure.java.jdbc$db_do_prepared.invokeStatic(jdbc.clj:1062)" "clojure.java.jdbc$db_do_prepared.invoke(jdbc.clj:1042)" "clojure.java.jdbc$execute_BANG_$execute_helper__18884.invoke(jdbc.clj:1446)" "clojure.java.jdbc$execute_BANG_.invokeStatic(jdbc.clj:1450)" "clojure.java.jdbc$execute_BANG_.invoke(jdbc.clj:1417)" "toucan.db$execute_BANG_.invokeStatic(db.clj:424)" "toucan.db$execute_BANG_.doInvoke(db.clj:419)" "clojure.lang.RestFn.invoke(RestFn.java:410)" "toucan.db$simple_delete_BANG_.invokeStatic(db.clj:750)" "toucan.db$simple_delete_BANG_.invoke(db.clj:735)" "toucan.db$simple_delete_BANG_.invokeStatic(db.clj:753)" "toucan.db$simple_delete_BANG_.doInvoke(db.clj:735)" "clojure.lang.RestFn.invoke(RestFn.java:445)" "toucan.db$delete_BANG_.invokeStatic(db.clj:768)" "toucan.db$delete_BANG_.doInvoke(db.clj:755)" "clojure.lang.RestFn.invoke(RestFn.java:439)" "--> models.database$pre_delete.invokeStatic(database.clj:71)" "models.database$pre_delete.invoke(database.clj:68)" "api.database$fn__54019.invokeStatic(database.clj:492)" "api.database$fn__54019.invoke(database.clj:487)" "middleware.auth$enforce_authentication$fn__66128.invoke(auth.clj:14)" "routes$fn__67481$fn__67482.doInvoke(routes.clj:56)" "middleware.exceptions$catch_uncaught_exceptions$fn__66227.invoke(exceptions.clj:104)" "middleware.exceptions$catch_api_exceptions$fn__66224.invoke(exceptions.clj:92)" "middleware.log$log_api_call$fn__67857$fn__67858.invoke(log.clj:178)" "middleware.log$log_api_call$fn__67857.invoke(log.clj:172)" "middleware.security$add_security_headers$fn__66190.invoke(security.clj:121)" "middleware.json$wrap_json_body$fn__67562.invoke(json.clj:64)" "middleware.json$wrap_streamed_json_response$fn__67580.invoke(json.clj:100)" "middleware.session$bind_current_user$fn__62721$fn__62722.invoke(session.clj:209)" "middleware.session$do_with_current_user.invokeStatic(session.clj:184)" "middleware.session$do_with_current_user.invoke(session.clj:177)" "middleware.session$bind_current_user$fn__62721.invoke(session.clj:208)" "middleware.session$wrap_current_user_id$fn__62706.invoke(session.clj:161)" "middleware.session$wrap_session_id$fn__62650.invoke(session.clj:125)" "middleware.auth$wrap_api_key$fn__66136.invoke(auth.clj:27)" "middleware.misc$maybe_set_site_url$fn__67884.invoke(misc.clj:56)" "middleware.misc$bind_user_locale$fn__67887.invoke(misc.clj:72)" "middleware.misc$add_content_type$fn__67872.invoke(misc.clj:28)" "middleware.misc$disable_streaming_buffering$fn__67895.invoke(misc.clj:87)"), :sql-exception-chain ["PSQLException:" "Message: ERROR: update or delete on table \"report_card\" violates foreign key constraint \"fk_card_label_ref_card_id\" on table \"card_label\"" "Detail: Key (id)=(23) is still referenced from table \"card_label\"." "SQLState: 23503" "Error Code: 0"]}

Below I am posting "Diagnostic Info", please let me know if you have any questions and how I can proceed with the Deletion of this Database Connection.
{
"browser-info": {
"language": "en-US",
"platform": "MacIntel",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.5+10",
"java.vendor": "AdoptOpenJDK",
"java.vendor.url": "https://adoptopenjdk.net/",
"java.version": "11.0.5",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.5+10",
"os.name": "Linux",
"os.version": "4.4.23-31.54.amzn1.x86_64",
"user.language": "en",
"user.timezone": "GMT"
},
"metabase-info": {
"databases": [
"mysql"
],
"hosting-env": "elastic-beanstalk",
"application-database": "postgres",
"run-mode": "prod",
"version": {
"date": "2020-01-13",
"tag": "v0.34.1",
"branch": "release-0.34.x",
"hash": "265695c"
},
"settings": {
"report-timezone": "US/Mountain"
}
}

Hi @ana.zapata
Go to the Postgres RDS that is configured as your application database and truncate the two tables label and card_label.

1 Like

How can I connect to the RDS database, are there default credentials for this database?

@ana.zapata No, those are generated, when you created the RDS. You'll need to look in your AWS control panel to find those.