<div dir="ltr">Hi Vadim!<br><br>The datatype that is specifed in attribute definition is a normal Python type. In Python, `int` and `str` types can be used immediately, but `date` and `datetime` types must be imported from stadard `datetime` module.<br>
<br>You can add this import to the beginning of your program:<br><br> from datetime import date, datetime<br><br>After that, all should work without the exception:<br><br> <span style="font-size:13px;font-family:arial,sans-serif">date = Required(date)<br>
</span> updated_at = Optional(datetime)<br><br>Alternatively, you can just import `datetime` module itself:<br><br> import datetime<br><br>After that, refer to `date` and `datetime` types as `datetime.date` and `datetime.datetime`:<br>
<br> <span style="font-family:arial,sans-serif;font-size:13px">date = Required(datetime.date)</span><br> updated_at = Optional(datetime.datetime)<br><br>Regards,<br>Alexander Kozlovsky<br><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Jul 31, 2014 at 2:33 PM, Вадим Бажов <span dir="ltr"><<a href="mailto:vadim@ideco.ru" target="_blank">vadim@ideco.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi people !<br>
<br>
Whenever i create a date or datetime field in entity python always gives me an exception:<br>
<br>
"NameError: name 'date' is not defined" for "date = Required(date)" record according your documentation documentation<br>
<br>
"pony.orm.core.ERDiagramError: Entity definition date was not found" for "date = Required('date')"<br>
<br>
I am trying to run i file with folowing code:<br>
<br>
#!/usr/bin/python<br>
<br>
# -*- coding: utf-8 -*-<br>
<br>
from pony.orm import *<br>
<br>
db = Database('sqlite', 'db.sqlite', create_db=True)<br>
<br>
class subscribers(db.Entity):<br>
<br>
id = PrimaryKey(int, auto=True)<br>
<br>
email = Optional(str)<br>
<br>
date = Required(date)<br>
<br>
sql_debug(True)<br>
<br>
db.generate_mapping(create_<u></u>tables=True)<br>
<br>
<br>
Running that code from python shell gives me the following:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
from pony.orm import *<br>
</blockquote></blockquote></blockquote>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
db = Database('sqlite', '/tmp/db.sqlite', create_db=True)<br>
</blockquote></blockquote></blockquote>
<br>
GET NEW CONNECTION<br>
<br>
RELEASE CONNECTION<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
class subscribers(db.Entity):<br>
</blockquote></blockquote></blockquote>
<br>
... id = PrimaryKey(int, auto=True)<br>
<br>
... email = Optional(str)<br>
<br>
... date = Required('date')<br>
<br>
...<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
sql_debug(True)<br>
</blockquote></blockquote></blockquote>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
db.generate_mapping(create_<u></u>tables=True)<br>
</blockquote></blockquote></blockquote>
<br>
Traceback (most recent call last):<br>
<br>
File "<stdin>", line 1, in <module><br>
<br>
File "<auto generated wrapper of generate_mapping() function>", line 2, in generate_mapping<br>
<br>
File "/usr/local/lib/python2.7/<u></u>dist-packages/pony/orm/core.<u></u>py", line 2698, in _resolve_attr_types_<br>
<br>
throw(ERDiagramError, 'Entity definition %s was not found' % py_type)<br>
<br>
File "/usr/local/lib/python2.7/<u></u>dist-packages/pony/utils.py", line 126, in throw<br>
<br>
raise exc # Set "pony.options.CUT_TRACEBACK = False" to see full traceback<br>
<br>
pony.orm.core.ERDiagramError: Entity definition date was not found<br>
<br>
<br>
So database can't be created after all.<br>
<br>
Pony version installed with pip:<br>
<br>
pony - Pony Object-Relational Mapper<br>
<br>
INSTALLED: 0.5.1<br>
<br>
LATEST: 0.5-beta<br>
<br>
Is it a bug or something? How i should create a datefield with Pony ?<br>
<br>
I've couldn't create a table with several tables with Pony until i commented out all datefields strings from the code. So Pony works if i don't use datetime fields.<br>
<br>
<br>
-- <br>
С уважением,<br>
Бажов Вадим,<br>
Инженер отдела технической поддержки,<br>
Компания Айдеко<br>
--<br>
Телефоны: +7 (495) 987-32-70; +7 (495) 662-87-34 (тех. поддержка); +7 (343) 345-15-75; Факс: +7 (343) 383-75-13<br>
<br>
Электронная почта:<br>
Вопросы по приобретению: <a href="mailto:sales@ideco.ru" target="_blank">sales@ideco.ru</a><br>
Технические вопросы: <a href="mailto:support@ideco.ru" target="_blank">support@ideco.ru</a><br>
Партнерство: <a href="mailto:partners@ideco.ru" target="_blank">partners@ideco.ru</a><br>
Общие вопросы: <a href="mailto:info@ideco.ru" target="_blank">info@ideco.ru</a><br>
<br>
Сайт: <a href="http://www.ideco.ru/" target="_blank">http://www.ideco.ru/</a><br>
Форум: <a href="http://www.ideco.ru/forum/" target="_blank">http://www.ideco.ru/forum/</a><br>
<br>
______________________________<u></u>_________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">https://mailman-mail5.<u></u>webfaction.com/listinfo/<u></u>ponyorm-list</a><br>
</blockquote></div><br></div>