I should first mention that I'm using SqlAlchemy through Flask-SqlAlchemy. I don't believe this affects the issue but if it does, please let me know.
Here is the relevant part of the error message I'm getting when running the create_all function in SqlAlchemy
InterfaceError: (InterfaceError) Error binding parameter 4 - probably unsupported type. u'INSERT INTO podcasts (feed_url, title, url, last_updated, feed_data) VALUES (?, ?, ?, ?, ?)' (u'http://example.com/feed', u'Podcast Show Title', u'http://example.com', '2012-04-17 20:28:49.117000'
Here is my model:
class Podcast(db.Model):
import datetime
__tablename__ = 'podcasts'
id = db.Column(db.Integer, primary_key=True)
feed_url = db.Column(db.String(150), unique=True)
title = db.Column(db.String(200))
url = db.Column(db.String(150))
last_updated = db.Column(db.DateTime, default=datetime.datetime.now)
feed_data = db.Column(db.Text)
def __init__(self, feed_url):
import feedparser
self.feed_url = feed_url
self.feed_data = feedparser.parse(self.feed_url)
self.title = self.feed_data['feed']['title']
self.url = self.feed_data['feed']['link']
Can someone tell me how I can get this to work? I've also tried the following model but that also doesn't work. Same error.
class Podcast(db.Model):
import datetime
__tablename__ = 'podcasts'
id = db.Column(db.Integer, primary_key=True)
feed_url = db.Column(db.String(150), unique=True)
title = db.Column(db.String(200))
url = db.Column(db.String(150))
last_updated = db.Column(db.DateTime)
feed_data = db.Column(db.Text)
def __init__(self, feed_url):
import feedparser
self.feed_url = feed_url
self.feed_data = feedparser.parse(self.feed_url)
self.last_updated = datetime.datetime.now()
self.title = self.feed_data['feed']['title']
self.url = self.feed_data['feed']['link']
Try to use datetime.datetime.utcnow()
. This works for me.
last_updated = db.Column(db.DateTime, default=db.func.current_timestamp())
I think this will work.
Set the import out the class.
from datetime import datetime
last_updated = db.Column(db.DateTime, default=datetime.now())
or
import datetime
last_updated = db.Column(db.DateTime, default=datetime.datetime.now())
I did this
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