I am trying to create database and insert values in it. I am using postgres database. I do not see any error when I do following
>>> from sqlalchemy import create_engine
>>> engine = create_engine('postgresql://postgres:password@localhost:5432/mydatabase')
>>> from sqlalchemy.ext.declarative import declarative_base
>>> Base = declarative_base()
>>> from sqlalchemy import Column, Integer, String
>>> class User(Base):
... __tablename__ = 'users'
... id = Column(Integer, primary_key=True)
... fullname = Column(String)
... password = Column(String)
...
... def __repr__(self):
... return "<User(name='%s', fullname='%s', password='%s')>" % (self.name, self.fullname, self.password)
>>> User.__table__
gives me
Table('users', MetaData(bind=None), Column('id', Integer(), table=<users>, primary_key=True, nullable=False), Column('fullname', String(), table=<users>), Column('password', String(), table=<users>), schema=None)
But when I run
>>> Base.metadata.create_all(engine)
Nothing shows up, In document it is given that table and its attributes are shown But nothing is seen after running Base.metadata.create_all(engine)
Could some body suggest some solution ?
If you want to see the commands SQLAlchemy is sending, you want to turn echo
on in the engine:
engine = create_engine('postgresql://...', echo=True)
Of course, you could always just look at the database afterwards with psql
or another tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With