since these two columns have a ForeignKey on them, neither should default to using autoincrement behavior within the DDL phase.
the error you are getting indicates that when you created a Component() object, one or both of these columns was not provided with an explicit value to be INSERTed. as for why it's "ignoring the values you provide" that can't be answered without a specific reproduction case. if the column does not have autoincrement, an explicit value must be provided to the object, *or* since these are foreign key columns, it implies you probably want to have the relationship() construct on other classes reponsible for populating these columns. it is also possible that if you do have relationship() constructs that refer to populating these columns, they might be stepping over your manually-provided values (although this is not what the error looks like), but again would need to see a complete example to know if something like that is happening here. On Wed, Dec 16, 2020, at 4:04 PM, Larry Martell wrote: > Is there any way to have a Non auto increment integer primary key? I > have this model: > > class Component(Base): > __tablename__ = 'Component' > > appCode = Column(ForeignKey('Application.appCode'), > primary_key=True, nullable=False) > componentEnumID = Column(ForeignKey('Enumeration.enumID'), > primary_key=True, nullable=False, autoincrement=False) > > And when I try and insert into it I get this warning: > > Column 'Component.componentEnumID' is marked as a member of the > primary key for table 'Component', but has no Python-side or > server-side default generator indicated, nor does it indicate > 'autoincrement=True' or 'nullable=True', and no explicit value is > passed. Primary key columns typically may not store NULL. Note that as > of SQLAlchemy 1.1, 'autoincrement=True' must be indicated explicitly > for composite (e.g. multicolumn) primary keys if > AUTO_INCREMENT/SERIAL/IDENTITY behavior is expected for one of the > columns in the primary key. > > And it ignores the values I provide for componentEnumID and generates > SQL without that column, which then fails with: > > Cannot insert the value NULL into column 'componentEnumID', table > 'DEC_CORE.dbo.Component'; column does not allow nulls. INSERT fails. > > How to get around this issue? > > -- > 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/CACwCsY5rmMQaTmHBeFsuOcum1wT7-mG1UOAm%2BJQhDVaqyqsCwA%40mail.gmail.com. > -- 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/fabf2109-f8eb-4be0-a8ce-0d2fe4363303%40www.fastmail.com.