On 06/07/2017 07:01 PM, Michael wrote:
Thanks for the insight Mike. I guess the best way to go about that would be to just call the raw insert sql statemen in the migration? like in https://stackoverflow.com/questions/23206562/sqlalchemy-executing-raw-sql-with-parameter-bindings/23206636#23206636

i'd start with that just to make sure it gets it working. From there, we do support insert().from_select(select()) if you have the inclination to build a Core SQL statement out of it but if you are only targeting Postgresql it's not critical.

http://docs.sqlalchemy.org/en/latest/core/dml.html?highlight=insert%20from_select#sqlalchemy.sql.expression.Insert.from_select

Since this app is not in production yet, would it be easier to make the current schema the initial schema and just insert the data that is in the MediaChapter table into the new schema just once? I guess could use bulk_insert() to do that?

if the data is not there yet, sure it's easier to start with a blank slate if that's what you mean....


On Wednesday, June 7, 2017 at 6:14:39 PM UTC-4, mike bayer wrote:



    On 06/07/2017 04:44 PM, Michael wrote:
     > Hi all, I have a class called MediaChapter(Base), which I've
    refactored
     > into MediaBase(Base) and MediaChapter(MediaBase) When I run the
     > migration, I see:
     >
     > |
     > psycopg2.IntegrityError:insert orupdate on table
    "mediachapter"violates
     > foreign key constraint "fk_mediachapter_id_mediabase"
     > DETAIL:Key(id)=(570)isnotpresent intable "mediabase".


    here's the real error with the SQL:

    sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) insert or
    update on table "mediachapter" violates foreign key constraint
    "fk_mediachapter_id_mediabase"
    DETAIL:  Key (id)=(570) is not present in table "mediabase".
       [SQL: 'ALTER TABLE mediachapter ADD CONSTRAINT
    fk_mediachapter_id_mediabase FOREIGN KEY(id) REFERENCES mediabase
    (id)']

    the error means that your "mediachapter" table contains an id, "570",
    which is not present in the "mediabase" table.

    it looks like you are starting with a populated "mediachapter" table
    then adding a new table "mediabase".  Before you create the constraint,
    you need to run an INSERT on "mediabase" that selects from
    "mediachapter", like:

    INSERT INTO mediabase (id, col1, col2, ...) SELECT id, col1, col2, ..
    FROM mediachapter



--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsubscr...@googlegroups.com <mailto:sqlalchemy-alembic+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to