6

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 ?

0

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.