On Thursday, September 5, 2019 at 8:58:16 AM UTC-4, Riccardo Cagnasso wrote:
>
> I don't think so. Wouldn't postgres prevented me deleting the column if it 
> were? 
>

PostgreSQL will prevent you from deleting the column if it were a 
CONSTRAINT, but would not necessarily notice it on a trigger / function.

I would check the db to see if there are any triggers/functions that used 
that column.

I would also trash any/all .pyc and .pyo files (or other compiled filed) to 
make sure you're not picking up an old file. That sometimes happens.



For example:


 CREATE TABLE foo_bar (
 id INT PRIMARY KEY,
 foo BOOLEAN DEFAULT NULL,
 bar BOOLEAN DEFAULT NULL
 );


 CREATE OR REPLACE FUNCTION foo_bar__trigger() RETURNS trigger AS 
$foo_bar__trigger$
 BEGIN
 IF NEW.foo is True
 THEN
 NEW.bar := True;
 END IF;
 RETURN NEW;
 END;
 $foo_bar__trigger$ LANGUAGE plpgsql;


 DROP TRIGGER IF EXISTS foo_bar__trigger on foo_bar;


 CREATE TRIGGER foo_bar__trigger BEFORE INSERT OR UPDATE ON foo_bar
 FOR EACH ROW EXECUTE PROCEDURE foo_bar__trigger();


 ALTER TABLE foo_bar DROP foo;
 
 INSERT INTO foo_bar (id, foo) VALUES (1, True);



That creates this error:

ERROR: record "new" has no field "bar"
 CONTEXT: PL/pgSQL function foo_bar__trigger() line 5 at assignment


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/5e927026-97a5-4bd9-ab5f-6ca6df700108%40googlegroups.com.

Reply via email to