Python SQLAlchemy插入

时间:2018-08-21 00:21:43

标签: python mysql sqlalchemy

此脚本没有任何错误,但是由于某种原因,它只是没有将测试数据插入MySQL / MariaDB数据库中。谁能告诉我我在想什么?

from sqlalchemy.sql import *
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker

engine = create_engine('mysql+pymysql://username:P4ssw0rd@127.0.0.1/telecom')
# define meta information
metadata = MetaData(bind=engine)
npanxx = Table('npanxx', metadata, autoload=True)

conn = engine.connect()
metadata = MetaData()
Session = sessionmaker(bind=conn)
session = Session()

# insert
i = insert(npanxx)
i = i.values({"npanxx": "123456",
              "npa": "123",
              "nxx": '456',
              "main_city": 'Detroit',
              "company": 'ABC Co.',
              "zip_code": '75670',
              "switch_name": 'Wayne',
              "prefix_type": 'wireless',
              "introduced": ''
              })
session.execute(i)

0 个答案:

没有答案