Reputation: 25
I have a table,
class RMMASTST(Base):
__tablename__ = 'RMMASTST'
RecorderID = Column(String(50), primary_key=True)
metering_data = relationship("StatsMetering", backref="recorder")
Now, I want to create a second table:
class StatsMetering(Base):
__tablename__ = 'StatsMetering'
RecorderID = Column(String(50), ForeignKey(RMMASTST.RecorderID), primary_key=True)
However, when I execute the script, I get the following error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Column 'RMMASTST.RecorderID' is not the same length or scale as referencing column 'StatsMetering.RecorderID' in foreign key 'FK__StatsMete__Recor__4B7734FF'. Columns participating in a foreign key relationship must be defined with the same length and scale. (1753) (SQLExecDirectW)")
Does anyone know why I keep on getting this error? Obviously, these are extracts from the script. All tables are created by using:
Base.metadata.create_all(Engine)
Upvotes: 0
Views: 96
Reputation: 25
The code as posted works correctly, if you get this type of error, just make sure that no tables were created already that might have different lengths.
Upvotes: 0