Hello list, I'm new to sqlalchemy and database programming. I have
defined a declarative class
import sqlalchemy as SQL
import sqlalchemy.ext.declarative as Declare
import sqlalchemy.orm as ORM
import datetime
Base = Declare.declarative_base()
class CUniversity(Base):
__tablename__ = "universities"
id = SQL.Column(SQL.Integer, primary_key=True)
Name = SQL.Column(SQL.String)
State = SQL.Column(SQL.String)
Rankprof = SQL.Column(SQL.Integer)
RankTotal = SQL.Column(SQL.Integer)
Deadline = SQL.Column(SQL.Date)
Status = SQL.Column(SQL.String)
Comment = SQL.Column(SQL.Text)
def __init__(self, name, state, rank_prof, rank_total, deadline,
status, comment):
self.Name = name
self.State = state
self.Rankprof = rank_prof
self.RankTotal = rank_total
self.Deadline = deadline
self.Status = status
self.Comment = comment
def __repr__(self):
return '\n'.join(["Name: " + self.Name,
"State: " + self.State,
"Professional rank: " + str(self.Rankprof),
"Total rank: " + str(self.RankTotal),
"Deadline: " + str(self.Deadline),
"Status: " + self.Status,
"Comment: " + self.Comment])
And I add an entry to a database using the following procedue:
DBPATH = "data.db"
Engine = SQL.create_engine("sqlite:///" + DBPATH)
MData = Base.metadata
UniTable = CUniversity.__table__
MData.create_all(Engine)
CSession = ORM.sessionmaker(bind=Engine)
Session = CSession()
TempDate = datetime.date(2009, 1, 15)
TestUni = CUniversity("CMU", "PA", "29", 0, TempDate, "", "Rec
form, No app. fee")
Session.add(TestUni)
Session.commit()
Python issued an error on the commit() operation:
OperationalError: (OperationalError) table universities has no
column named Rankprof u'INSERT INTO universities ("Name", "State",
"Rankprof", "RankTotal", "Deadline", "Status", "Comment") VALUES
(?, ?, ?, ?, ?, ?, ?)' ['CMU', 'PA', '29', 0, '2009-01-15', '', 'Rec
form, No app. fee']
What did I do wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---