Did you run this code more than once, adding the RankProf column
between runs? If so, the universities table in data.db database would
not have the column RankProf defined. The metadata create_all() method
does not replace existing tables.
One approach, especially for a test program, is to add a call to
drop_all() before the call to create_all(). Another, if you don't need
the database on disk, is to use a SQLite in memory database for
testing, change the database name to ":memory:".


On Dec 6, 7:18 am, Corsair <[EMAIL PROTECTED]> wrote:
> 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 sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to