2

I want to delete a row in my table re_users and I am getting error below:

ERROR:  null value in column "user_id" violates not-null constraint
DETAIL:  Failing row contains (5, null, 2014-09-05 06:53:47.804037, 2014-09-05 06:53:47.804037, null, _fetch_mails, minutes, null, Fetchmail Service, (), -1, 2014-09-05 06:53:47, 5, f, f, 5, fetchmail.server).
CONTEXT:  SQL statement "UPDATE ONLY "public"."ir_cron" SET "user_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "user_id""

kindly suggest me, how do I resolve it.

Waiting for reply.

Thanks

user88
  • 1,174
  • 3
  • 27
  • 51
  • 2
    Do delete a row you need to use a `delete` statement, not an `update` statement. –  Feb 02 '15 at 13:31
  • my delete statement is `delete from res_users where login = 'admin'` and login is my column name. – user88 Feb 02 '15 at 13:32
  • 3
    Do you have any foreign keys defined with `on delete update`? –  Feb 02 '15 at 13:33

2 Answers2

1

The table ir_cron contains a row with the user_id that you're trying to delete, you should first edit that row or delete it before deleting the row in re_users.

1

This is postgres' way of telling you there's a foreign key relationship that needs to be deleted first. Once you delete the row in your linked table, then you'll be able to get past this error.

Related: How to query a table for foreign keys?

Kellen Stuart
  • 7,775
  • 7
  • 59
  • 82