I want to populate a fresh database with inital data stored in csv files. I tried to use odo to populate an existing table with the content of a csv file. My files do not have a primary key and the number of columns do not match as the database has additional columns defined.
How can I use odo to achieve this?
from sqlalchemy import Column, String, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Test(Base):
__tablename__ = 'testtable'
uid = Column(Integer, primary_key=True)
colA = Column(String(50))
colB = Column(String(50))
comment = Column(String(100))
engine = create_engine('sqlite:///testdb.db')
Base.metadata.create_all(engine)
My csvfile looks like this:
col A;col B
aa;bb
ax;bx
This does not work:
from odo import odo
odo('csvfile.csv',
'sqlite:///testdb.db::testtable',
has_header=True)
Error message:
expected 4 columns but found 3 - filling the rest with NULL
INSERT failed: datatype mismatch