Pylons / pyramid_blogr

Pyramid_blogr is an example implementation of Flaskr app with Pyramid Web Framework
73 stars 39 forks source link

not able to edit the blog entires #63

Closed pendyalarajesh123 closed 7 years ago

pendyalarajesh123 commented 7 years ago

Hi,

I am able to create entries in DB, but when i tried to edit the entries, getting the error " ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update identity column 'id'. (8102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)") [SQL: u'UPDATE entries SET id=?, body=? WHERE entries.id = ?'] [parameters: (u'7', u'for testing in pyramid framework', 7)]".

Please some one help me on this.

ergo commented 7 years ago

I'm affraid I never used MSSQL.

It looks like there a type mismatch for ID - you try to use string for int? Why are you trying to update the pkey in the first place?

pendyalarajesh123 commented 7 years ago

I am not updating the pkey, when I tried to update the title and blog content, it is redirecting and trying to update the ID which is the primary key. I took the source code from here and changed the sqlalchemy.url in development.ini file.

ergo commented 7 years ago

Ok,

I think I know the cause - I will update the example soon.

pendyalarajesh123 commented 7 years ago

Thanks in advance.

pendyalarajesh123 commented 7 years ago

Hi ergo, can you please give some updates on the above issue?

ergo commented 7 years ago

@pendyalarajesh123

I think the reason this happens is that here:

https://github.com/Pylons/pyramid_blogr/blob/master/pyramid_blogr/views/blog.py#L39

the form tries to use: https://github.com/Pylons/pyramid_blogr/blob/master/pyramid_blogr/forms.py#L13

the 'id' from the form is used as string - you can try changing BlogUpdateForm to BlogCreateForm in the view and this should fix the issue for you.

I'll update the tutorial (along with 1.8 changes) when I find the time.

pendyalarajesh123 commented 7 years ago

Hi ergo, thanks for the information.

I changed the view blog.py in #line 39 as "form = BlogCreateForm(request.POST, entry)", still I am getting the below error.

"UndefinedError: 'pyramid_blogr.forms.BlogCreateForm object' has no attribute 'id'"

ergo commented 7 years ago

@pendyalarajesh123 please do https://docs.python.org/3/tutorial/ first to understand the basics of python programming, you should have much easier time to follow the tutorial.

pendyalarajesh123 commented 7 years ago

Thanks for the info.

ergo commented 7 years ago

Should be fixed in latest version of tutorial