How can I access a Posgres DATE column with SQLAlchemy?

Viewed 71

I would like to do one API Rest with connection with Postgres SQL.

I'm just starting programing with Python, so be easy with me...hehehe

That's the code that I have:

**** Postgres Database ****

--drop TABLE Employee;
CREATE TABLE Employee
(
    id      numeric(10) NOT NULL,
    name    varchar(50) NOT NULL,
    data    date NOT NULL,
    PRIMARY KEY (id)
);

**** No Pycharm *****

from flask_sqlalchemy import SQLAlchemy
from flask import Flask, render_template
from datetime import date

app = Flask(__name__)

app.config["SQLALCHEMY_DATABASE_URI"] = 'postgresql://user:password@X.X.X.X:5432/correntista'
db = SQLAlchemy(app)


#The connection to the database is Ok!

class Employee(db.Model):
        __tablename__ = "employee"
        id = db.Column(db.NUMERIC(10), primary_key=True)
        name = db.Column(db.VARCHAR)
        data = db.column(db.DATE)

@app.route("/")
def index():

        emp_data = Employee.query.all()

        for emp in emp_data:
                print(emp.data) 

**I don't know why I receiving error.

enter image description here

When I remove the column DATE and run works fine **

I really need your help!

Thanks :)

0 Answers
Related