AttributeError: type object 'Query' has no attribute 'from_json'

434 views
Skip to first unread message

Taehwan Kim

unread,
Aug 10, 2015, 5:43:39 PM8/10/15
to Wagtail support
Thanks wagtail team.
I am working on second project using wagtail and deploying now.
After deploy and test, I tried to edit page's content and click publish but got internal server error. 


Internal Server Error: /admin/pages/6/edit/
Traceback (most recent call last):
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get$
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/views/decorators/cache.py", line 43, in $
    response = viewfunc(request, *args, **kw)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 22, in$
    return view_func(request, *args, **kwargs)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailadmin/views/pages.py", line 252,$
    revision.publish()
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailcore/models.py", line 1141, in p$
    page = self.as_page_object()
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailcore/models.py", line 1097, in a$
    obj = self.page.specific_class.from_json(self.content_json)
AttributeError: type object 'Query' has no attribute 'from_json'


or this

Internal Server Error: /admin/pages/3/edit/
Traceback (most recent call last):
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get$
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/views/decorators/cache.py", line 43, in $
    response = viewfunc(request, *args, **kw)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 22, in$
    return view_func(request, *args, **kwargs)
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailadmin/views/pages.py", line 252,$
    revision.publish()
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailcore/models.py", line 1141, in p$
    page = self.as_page_object()
  File "/home/tyndale/.virtualenvs/tyndale/lib/python3.4/site-packages/wagtail/wagtailcore/models.py", line 1097, in a$
    obj = self.page.specific_class.from_json(self.content_json)
AttributeError: type object 'Image' has no attribute 'from_json'


what is my problem?

Matthew Westcott

unread,
Aug 10, 2015, 5:58:41 PM8/10/15
to wag...@googlegroups.com
It looks like the 'content types' table has got mixed up. Django populates this automatically during migration, and won't necessarily do it in the same order on different installations of the same site - so if you've imported data from your development site, and NOT imported the django_content_types table at the same time, this would cause problems like the ones you're seeing.

If you're using './manage.py dumpdata', you need to include 'contenttypes' in the list of apps. Usually it's easier to dump the entire database at the SQL level, though (using PostgreSQL's pg_dump utility, for example).

Cheers,
- Matt

Taehwan Kim

unread,
Aug 11, 2015, 1:15:28 AM8/11/15
to Wagtail support
Thanks.
i did pg_dump database_name > data.sql
then I have data.sql.

How can I load data into database in production server (like using python manage.py loaddata)?
I googled but there are too much information, so I am kinda confused. :(

I did 
psql -d database_name -f data.sql.

but it copied schema not real data.
Please help~

Matthew Westcott

unread,
Aug 11, 2015, 5:46:03 AM8/11/15
to wag...@googlegroups.com
Those commands look correct to me. Have you checked that your data is included in the data.sql file? (Normally there would be a COPY statement for each table, with the table data following it.) Do you get any error messages when running pg_dump or psql?

Are you running the 'psql' command on an empty database? (It's possible to get pg_dump to output the necesary DROP TABLE commands, but I find that this doesn't work too well when there are foreign key constraints.) I usually drop and recreate the database before running the import:
dropdb database_name
createdb database_name

Cheers,
- Matt

Taehwan Kim

unread,
Aug 11, 2015, 10:59:51 AM8/11/15
to Wagtail support
OK,
When I dump it, there are no errors,
but when I did
 
psql -d database_name -f data.sql.

I see

ERROR: must be superuser to COPY to or from a file
HINT:  Anyone can COPY to stdout or from stdin. psql's \copy command  also works for anyone

I don't understand :(
I am a owner of database and sudoer. but cant' sudo psql -d database_name -f data.sql.

:(

Taehwan Kim

unread,
Aug 11, 2015, 12:33:04 PM8/11/15
to Wagtail support
OK
I found out why I got that error.

Because of ownership of data.sql file.
So When I dump it, I have to do like this

pg_dump -O database_name > data.sql (No Owener)

then It worked. 

And Question...
When I want to dump and load data into production server, Do I have to drop database and recreate it? 'cause I tried without dropping database, it seems not loading data into server :( strange,,

Matthew Westcott

unread,
Aug 11, 2015, 12:47:26 PM8/11/15
to wag...@googlegroups.com
On 11 Aug 2015, at 17:33, Taehwan Kim <redleo...@gmail.com> wrote:
> And Question...
> When I want to dump and load data into production server, Do I have to drop database and recreate it? 'cause I tried without dropping database, it seems not loading data into server :( strange,,

Yes - by default the dump.sql file doesn't include DROP TABLE statements, so when you run it on an existing database it will try to create tables that already exist.

You can tell pg_dump to output DROP TABLE statements with the -c switch, but I've found that this doesn't work very well when your database has foreign key constraints (because then the tables have to be dropped in a specific order) - it's more reliable to simply drop and recreate the database.

Cheers,
- Matt

Taehwan Kim

unread,
Aug 11, 2015, 12:58:02 PM8/11/15
to Wagtail support
Oh OK!
Thanks Matt!
Reply all
Reply to author
Forward
0 new messages