我无法覆盖列默认值。我为subject
和can_retry
插入了不同值的行。但是,当我检查表时,它仍然是Math
和False
。我在这里做错了什么?
from sqlalchemy import *
db = create_engine('sqlite:///myapp-quizzes.db')
metadata = MetaData(db)
quizzes = Table("quizzes", metadata,
Column("id", Integer, primary_key = True),
Column("subject", String, default = "Math"),
Column("description", String),
Column("answer_a", String),
Column("answer_b", String),
Column("answer_c", String),
Column("answer_d", String),
Column("can_retry", Boolean, default = False)
)
quizzes.create()
i = quizzes.insert()
i.execute({
"subject": "Biology",
"description": "Where is the heart?",
"answer_a": "In the head",
"answer_b": "In the arm",
"answer_c": "In the gut",
"answer_d": "Dunno",
"can_retry": True
})
答案 0 :(得分:0)
列表中的词典必须具有完全相同的键。当然这适用于多个带字典的插入。
quizz_list = [
{
...
'subject': 'Math',
'can_retry': False
},
{
...
'subject': 'Biology',
'can_retry': True
}
]