Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SQLAlchemy engine CREATE TABLE

  • execute
  • Engine
import os
from sqlalchemy import create_engine

dbname = 'test.db'
if os.path.exists(dbname):
    os.unlink(dbname)

engine = create_engine('sqlite:///' + dbname)  # Engine

engine.execute('''
    CREATE TABLE person (
        id INTEGER PRIMARY KEY,
        name VARCHAR(100) UNIQUE,
        balance INTEGER NOT NULL
    );
''')