python sqlalchemy插入

wyyhbhjk  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(265)

我没有发现这个脚本有任何错误,但由于某些原因,它只是没有将测试数据插入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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题