Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using TIMESTAMP in the created_at column fails with sqlite database #6

Open
ondiekelijah opened this issue Feb 8, 2022 · 2 comments

Comments

@ondiekelijah
Copy link

Congratulations on a job well done; that is an incredible series.

I recently run into an issue when using the TIMESTAMP with SQLite database.

Here's a brief of what's up.

With this ;

created_at = Column(TIMESTAMP(timezone=True), nullable=False, server_default=text('now()')

An exception is raised.

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "(": syntax error
E       [SQL: 
E       CREATE TABLE posts (
E               id INTEGER NOT NULL, 
E               title VARCHAR NOT NULL, 
E               content VARCHAR NOT NULL, 
E               published BOOLEAN DEFAULT 'TRUE' NOT NULL, 
E               created_at TIMESTAMP DEFAULT now() NOT NULL, 
E               PRIMARY KEY (id)
E       )
E       
E       ]
E       (Background on this error at: https://sqlalche.me/e/14/e3q8)

However, modifying the column to use DateTime works for both;

created_at = Column(DateTime(timezone=True), default=func.now())

Is there any chance that a fix for this will be available?

@mvarrone
Copy link

Hello! I see a problem. I think you are missing a ) at the end of the line.

It should be like this:

created_at = Column(TIMESTAMP(timezone=True),
                    nullable=False, server_default=text('now()'))

@jonathanbouchet
Copy link

I had the same issue but found a discussion there

Also I'm using SQLAlchemy==2.0.25 so that's different from the version Sanjeev has in his requirements.

from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime
from sqlalchemy.sql import func
created_at = Column(DateTime(timezone=True), server_default=func.now())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants