django + confusion with the ORM - django

I am getting a strange error despite following the documentation. I have the following model:
class UserToken(models.Model):
token = models.CharField(max_length=100)
user = models.ForeignKey(User)
Whenever I do UserToken.objects.get(token=tokenValue) (tokenValue is the value I am looking for) locally for MySQL, everything works. I get the value as expected. But when I do the same on my MySQL instance in Amazon RDS, I keep getting the following error:
ERROR Unknown exception: UserToken matching query does not exist.
Is there anything I am missing here? Why would a statement like this not work in RDS?
[EDIT]
Just to clarify, the token values do indeed exist. I checked the database just to make sure. Also I tried the following:
ut = UserToken.objects.raw("select * from user_token") (just to test..there was only one entry in the table) and i'm getting the following error: Unknown exception: 'RawQuerySet' object has no attribute 'token'. Is there a reason for this? The token field does exist.

I'm really not sure how this is different...but previously I was doing request.raw_post_data to get the json message that the user was sending me. I changed that to request.POST and request.body and somehow that fixed the issue. Just in case anybody else faces this hard-to-debug issue!

Related

Getting gskey: request denied

Hey trying to insert and update a list items on one of my tabs but i'm getting the error msg "gskey: request denied error".
I don't understand what this error means. Can someone please clarify what would be the cause for this error.
A call to the checkgskey function on the server side gives the "gskey: request denied" error if the X-GSREQ-KEY in the POST request is missing.
X-GSREQ-KEY is automatically transmitted by a dedicated parameter in either ajxpgn or reload tab. The content of the gskey is output by the emitgskey function.
emitgskey('unique_phrase');
checkgskey('unique_phrase');
As long as the two unique phrases match, the request is not blocked. The unique phrase acts as a seed to compute a protective challenge that's unique to the user, session and location. In a way, the purpose of a GSKey is similar to a nounce.
Additional documentation here.
Turns out the gskey wasn't being passed in with the call. You get that error when there's a key expected but not given.

Error writing to many to many field django rest framework api

This seems to be my solution https://stackoverflow.com/a/48636446/7989638 (for "How can I make a writable ManyToManyField with a Through Model in Django Rest Framework?
") but I am getting this error :
{"images":["Incorrect type. Expected pk value, received unicode."]}
their solution works in the create method of the serializer but i debugged and checked that it never reaches that method; returns error beforehand.
Could you please help me fix this.
Thanks

How to get Django Report Builder working properly?

Documentation provided by Burke isn't very thorough and there isn't a lot of information on Django Report Builder yet, not even youtube videos. Does anybody have any information on how to get work Report Builder Working in Django? I currently keep getting this error message:
(1146, "Table 'epic_test2.report_builder_report' doesn't exist")
I've installed it, but I can't create reports yet and the documentation I do have isn't very helpful. Any advice would be great! Thanks!
UPDATE TO POST/ 5.12.15 -
I fixed the first issue, but now I have a new error. :) Yay. It's a Field Error
"Cannot Resolve keyword 'name' into field. Choices are: app_label, id, logentry, model, permission, report.
ANY clues for this one would be helpful... going into third hour of troubleshooting. :)
Thanks!
~Heather
Sounds like you may need to run a migrate to create the Report Builder tables required.
python manage.py migrate
I would suggest you do a full search in your code for "name", something like: grep -R "name" ., and see where it's defined, is it a valid field in models.py, etc.
I've had similar error before, turned out, I updated my variable name from something like "name" to "new_name" in my model. The way report-builder works, it saves column (field) name in the database. If it's an old field name, there will be error. Luckily this is easy to fix: go to report-builder UI, remove the row for that column, then add the column back, then the new field name would be saved.
Hope this helps.

Object could not be found in database for SearchResult django haystack

I am using haystack with elasticsearch. I have build index data using rebuild_index command. But when I tried to search for object, its giving me following error:
"Object could not be found in database for SearchResult ' (pk=u'118')>'."
I have double checked in database, no records were deleted. But I am still getting this error.
Can anyone please help with it?
Thanks.
It looks like you are searching for your pk as a string and not an integer, not sure what your query looks like.
as integer, notice no quotes when defining pk_int:
pk_int = 118
Model.objects.get(pk = pk_int)
if your variable containing the pk is a string already, use int():
pk_string = '118'
Model.objects.get(pk = int(pk_string))
Answering it to mark it resolved.
It was database config issue. I am having different settings file for different environment, and was having mismatch for database config in both files.
For anyone coming from a web search engine, if the accepted answer doesn't work for you, you can also try rebuilding the index:
./manage.py rebuild_index
I had the same error message as the OP, and rebuilding the index solved my issue.

"Error: near "Documents": syntax Error" - sqlite3/Django

I am trying Chapter 6 from Django book.
After changing some fields to blank=True, and null=True, we are told to update the table using dbshell.
When I type: python manage.py dbshell, the following error appears:
C:\Users\Rafa\Documents\Python\book>python manage.py dbshell
Error: near: "Documents": syntax error.
I tried installing sqlite3.exe in my book directory and running directly from there. I still get the same error anytime I try to run a command. For example, once on the sqlite3 shell (opening executable file):
sqlite>ALTER TABLE books_book ALTER COLUMN publication_date DROP NOT NULL;
Error: near "ALTER": syntax error.
I know the commands may be wrong, but I can try anything and it will always point the same error and show the first word of the command in the "".
Any help?
SQLite has very limited ALTER TABLE support.
You have to drop and recreate the table.
As the error message suggests, there is a syntax error somewhere. You should check (or post here) the parts which describe Documents class for some syntactic mistakes :)
I realize now that Django does not support database migrations very well. Once you do the initial migration and the original table is set, it is impossible to add or modify fields with Django only. You need a database migration schema like South.