I keep getting the below error regarding the primary_key=True
. Please could someone point out where i'm going wrong. I'm trying to follow:
http://docs.sqlalchemy.org/en/latest/core/metadata.html#metadata-describing
from sqlalchemy import *
mydata123 = table("dailymarketdata", metadata,
column('data_id', mysql.BIGINT, primary_key=True),
column('dt', Date),
column('security_id', mysql.VARCHAR),
column('open', float),
column('high', float),
column('low', float),
column('close', float),
column('ma200', float),
column('rtrend', mysql.TINYINT))
TypeError Traceback (most recent call last)
<ipython-input-350-bd385371a391> in <module>()
2
3 mydata123 = table("dailymarketdata", metadata,
----> 4 column('data_id', mysql.BIGINT, primary_key=True),
5 column('dt', Date),
6 column('security_id', mysql.VARCHAR),
TypeError: column() got an unexpected keyword argument 'primary_key'
If I exclude primary_key=True
I get another error
`AttributeError: 'MetaData' object has no attribute 'key'
Python is a case sensitive language
column
and Column
are different callables in sqlalchemy.table
and Table
are also different callablesfloat
is the python data type, while the sqlalchemy type is Float
Try, rewriting your snippet as:
from sqlalchemy import *
from sqlalchemy.dialects import *
metadata = MetaData()
mydata123 = Table("dailymarketdata", metadata,
Column('data_id', mysql.BIGINT, primary_key=True),
Column('dt', Date),
Column('security_id', mysql.VARCHAR),
Column('open', Float),
Column('high', Float),
Column('low', Float),
Column('close', Float),
Column('ma200', Float),
Column('rtrend', mysql.TINYINT))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With