I'm trying load initial data into a flask-sqlalchemy project from a json file. This is the error that I'm getting.
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 0 - probably unsupported type.
[SQL: INSERT INTO user (name, twitter, linkedin, youtube, username) VALUES (?, ?, ?, ?, ?)]
[parameters: (['Susan Ariel Aaronson'], ['http://twitter.com/AaronsonSusan'], ['https://www.linkedin.com/in/susan-aaronson-b60bb45'], None, ['AaronsonSusan'])]
(Background on this error at: http://sqlalche.me/e/rvf5)
Here's how I'm trying to load the initial data. I imagine that I'm getting an error because the resulting data is a list and not a string.
from app import db
import json
from app.models import User
f = open('data.json')
data = json.loads(f.read())
print([data(**item[0]['username']) for item in data])
Here's my model:
from app import db
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from sqlalchemy import (
Column,
Integer,
String
)
class User(Base):
__tablename__ = 'User'
id = Column(Integer, primary_key=True)
name = Column(String(120), index=True, unique=True)
twitter = Column(String(120), index=True, unique=True)
linkedin = Column(String(120), index=True, unique=True)
youtube = Column(String(120), index=True, unique=True)
username = Column(String(120), index=True, unique=True)
def __repr__(self):
return '<User {}>'.format(self.name)
I've tried this answer: Extract first item of each sublist
But get a Keyerror:0 error when I try to add something like this: data_first = [item[0] for item in data]
Also, the json data doesn't have an id. Will it load without a primary key?