Thread: Does dropping a column from a table mess up foreign keys?

Does dropping a column from a table mess up foreign keys?

From
Keith F Irwin
Date:
I'm getting the following error:

    ERROR:  Relation "accounts" with OID 72496 no longer exists

What I did was to drop a couple of columns using the example Bruce
provides in his book on page 264.  Briefly, it's something like:

    create table temp as select * from accounts;
    drop table accounts;
    create table accounts (etc with columns missing);
    insert into accounts select <all except dropped cols> from temp;
    drop table temp;
    grant update,select,insert,delete on accounts to user;

And so on.  I've also updated an "accounts_view" based on this table so
that the dropped columns wouldn't appear (the view being defined with an
asterisk field list).

I have lots of tables with "references accounts(id)" in them.  Are these
going to be screwed up because of the drop/create above?

I even tried dumping the DB after the changes, then pg_restoring them, but
I get a message something like, Relation ACCOUNTS doesn't exist.  I was
thinking that restoring the db in this way would recalculate the OIDs.

Is there some command I should do BEFORE the changes due to the fact that
other tables have contraints based on "accounts"?  (Now that I think about
it, I'm amazed that I can drop a table with data dependent on it.)

 Clues?

Keith