I am trying to use SQLAlchemy's ORM layer (via Flask-SQLAlchemy==2.0), and I need to support (ingest and update) some tables that were created with Strings (Varchars) as primary keys. BTW, I am using SQLite as the backend during development, but the production datastore will be Oracle.
The following code was supposed to create the model, and then the test_setup function was supposed to initialize some test data, but I seemingly can only create tables with Integers as primary keys.
# MODEL
class MAG_BAG(db.Model):
"""An entity used for the test_setup"""
__tablename__ = 'DS_MAG_BAG'
BAG_ABBREV = db.Column(db.String(18), primary_key=True)
BAG_NM = db.Column(db.String(128))
MAGIC_POWER_DESCR = db.Column(db.String(128))
SORT_ORD = db.Column(db.Integer)
def __repr__(self):
return '<MAG_BAG {0}>'.format(self.BAG_NM)
def test_setup():
"""Only used during development or testing as a convenience."""
db.create_all() # why this no make DS_MAG_BAG?
#
if User.query.filter_by(login_id='felix').first() is None:
u = User.register('felix', 'cat')
e = Entity.register('Magic Bag', 'DS_MAG_BAG', u.id)
# u and e populate tables just fine
# but section below does nothing
for b in [('FSH','Magic Fish Sack'),('CANBAG','Canoe Bag'),('ESC', 'Escalator Bag')]:
print(a_bag)
a_bag = MAG_BAG(BAG_ABBREV=b[0], BAG_NM=b[1])
db.session.add(a_bag)
db.session.commit()
Is creation of tables with PKs of datatypes other than Numeric types possible?