Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

python databases, cant create tables in postgres

Heyo peoeple! :) so i'm at the python track and just started "Using databases in python"

i've followed the documentation prowided to setup postgres instead of Sqlite

but the code below only create a file called peewee.db and nothing in the database "python-development"

my platform is mac i have the newest version of postgres install thrue homebrew when loggin into the postgres console i can see my database python development with

\d

hovever when i mark the database and use :

\dt

to list the table it return "No relations found." also i can see that the data i just wrote end up in peewee.db

from peewee import *



db = PostgresqlDatabase(
    'python-development',  # Required by Peewee.
    user='teamtreehouse',  # Will be passed directly to psycopg2.
    password='12345',  # Ditto.
    host='localhost',  # Ditto.
)


class Student(Model):
    username = CharField(max_length=225, unique=True)
    points = IntegerField(default=0)

    class Meta:
        Database = db


if __name__ == '__main__':
    db.connect()
    Student.create_table()
    db.create_tables([Student], safe=True)
    Student.create(username='Adlex', points=4)
    db.close()

1 Answer

so it turns out that the problem was that i did'nt lowercase the ´´´python datebase = db ´´´ in the meta class caussed the problem