Default value doesn't work in sqlalchemy automap

Viewed 143

Suppose I have table main_table with columns:

id (AUTO_INCREMENT), first (int), value1 (double with default=0), value2 (double)

Using code

engine = sqlalchemy.create_engine(db_connect)
session = Session(engine)
base = automap_base()
base.prepare(engine, reflect=True)
table = getattr(base.classes, fact_table)
kwargs = {'first': 200016, 'value2': 1.0}
entry = table(**kwargs)
session.add(entry)
session.commit()

I got an error {"error": 500, "message": "(pymysql.err.IntegrityError) (1048, \"Column 'value1' cannot be null\")

It happens when value1 doesn't accept null value.

I'd like to ignore this and add entry after all value1 is not obligatory (has default).

SHOW CREATE TABLE main_table;:

CREATE TABLE `main_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first` int(11) NOT NULL,
  `value1` double(22,6) NOT NULL DEFAULT 0.000000,
  `value2` double(22,6) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8
1 Answers
Related