🤖
【Python】 SQLAlchemyの接続方法
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
engine = create_engine(
"XXXXXX接続URLXXXXXXX")
Base.metadata.create_all(bind=engine)
# Session の作成
session = sessionmaker(
autocommit=False,
autoflush=False,
bind=engine
)
# テーブルの作成
Base.metadata.create_all(bind=engine)
# テーブルの削除
Base.metadata.drop_all(engine)
Discussion