> I want to work with SQLAlchemy and bought the book 'Essential Alchemy'
> of O'Reilly. In chapter nine elixir is shown.
> I have now the following code in model.py:
It is missing a call to "setup_all()" after the model is defined (see
below). I supposed the book used Elixir version 0.3.0 or earlier. This
is a requirement which was introduced in version 0.4.
Without this call, Elixir doesn't do its job: create a mapper and
tables for your entities. This also implied that your create_all()
call below wouldn't create any tables in your database.
setup_all()
Hope it helps,
--
Gaëtan de Menten
http://openhex.org
The book says it works with 0.4 and 0.5.
> Without this call, Elixir doesn't do its job: create a mapper and
> tables for your entities. This also implied that your create_all()
> call below wouldn't create any tables in your database.
Now it works. ;-} And the tables where not created, yes. I was
wondering about that. The dummy.db was created, but it kept empty. Now
it is correctly filled.
Thanks.
There are more errors in the book. (Too many.)
For example it says that after
metadata.bind.echo = True
you should get a lot off explenationary info when you do
price = Price.get(1)
In the code is also price.store_name instead of price.store.name.
And when running the code I get:
#####
/usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
SAWarning: Unicode type received non-unicode bind param value 'Main
Store'
param.append(processors[key](compiled_params[key]))
/usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
SAWarning: Unicode type received non-unicode bind param value
'Secondary Store'
param.append(processors[key](compiled_params[key]))
#####
What do I need to do to get rid of this warning?
--
Cecil Westerhof
> For example it says that after
> metadata.bind.echo = True
> you should get a lot off explenationary info when you do
> price = Price.get(1)
Well, that should be the case indeed. That is, you should see the SQL
that is sent to the DB. Don't you see anything?
> And when running the code I get:
> #####
> /usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
> SAWarning: Unicode type received non-unicode bind param value 'Main
> Store'
> param.append(processors[key](compiled_params[key]))
> /usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
> SAWarning: Unicode type received non-unicode bind param value
> 'Secondary Store'
> param.append(processors[key](compiled_params[key]))
> #####
>
> What do I need to do to get rid of this warning?
pass unicode strings to unicode fields, as for example:
stores = [
Store(u'Main Store'),
Store(u'Secondary Store'),
]
No. After 'python -i dummy.py' I get the following dialog when
inputting some commands:
#####
$ python -i dummy.py
>>> metadata.bind.echo = True
>>> price = Price.get(1)
>>> price.store.name
u'Main Store'
>>> session.commit()
2008-08-12 13:28:18,568 INFO sqlalchemy.engine.base.Engine.0x..0c COMMIT
#####
>> And when running the code I get:
>> #####
>> /usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
>> SAWarning: Unicode type received non-unicode bind param value 'Main
>> Store'
>> param.append(processors[key](compiled_params[key]))
>> /usr/lib/python2.5/site-packages/sqlalchemy/engine/default.py:237:
>> SAWarning: Unicode type received non-unicode bind param value
>> 'Secondary Store'
>> param.append(processors[key](compiled_params[key]))
>> #####
>>
>> What do I need to do to get rid of this warning?
>
> pass unicode strings to unicode fields, as for example:
>
> stores = [
> Store(u'Main Store'),
> Store(u'Secondary Store'),
> ]
That works. I think I should send some errata to O'Reilly. ;-}
Thanks again.
--
Cecil Westerhof