It worked perfectly! Thank you!
El lunes, 2 de julio de 2018, 17:00:45 (UTC+2), Mike Bayer escribió:
>
> tables can be altered additively, sure
>
> from sqlalchemy import *
> from sqlalchemy.schema import CreateTable
>
> m = MetaData()
>
> # table w/ no PK
> t = Table(
> "nopk", m,
> Column('q', Integer),
> Column('p', Integer)
> )
>
> # add a column w/ pk=True
> t.append_column(Column('id', Integer, primary_key=True))
>
> print(CreateTable(t))
>
> # table w/ no PK
> t2 = Table(
> "nopk_2", m,
> Column('q', Integer),
> Column('p', Integer)
> )
>
> # add a new pk constraint, append_constraint knows how to replace
> # an empty pk constraint w/ a non-empty one
> t2.append_constraint(PrimaryKeyConstraint("q", "p"))
>
>
> print(CreateTable(t2))
>
>
>
> On Mon, Jul 2, 2018 at 10:09 AM, Javier Collado Jiménez
> <[email protected] <javascript:>> wrote:
> > Hello!
> > Is there a way to redefine a table in metadata?
> > I'm trying to define a table without pk to create this way in the
> database,
> > and then trying to add the pk to the definition to use it.
> > But I'm always getting this error
> > sqlalchemy.exc.ArgumentError: Column object 'column' already assigned to
> > Table 'table'
> > I'm using extend_existing=True but it doesn't work either.
> > Thank you in advance!
> >
> > --
> > 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 [email protected] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.