Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncdb seems to break #1

Open
mattkatz opened this issue Jun 10, 2010 · 4 comments
Open

syncdb seems to break #1

mattkatz opened this issue Jun 10, 2010 · 4 comments

Comments

@mattkatz
Copy link

to reproduce I start with no db in my django app.
I have wellknown as an app directory.
I add wellkown to my settings.py installed_apps
I add wellkown urls.py to my main urls.py
I run python manage.py syncdb

I get an error:
django.db.utils.DatabaseError: no such table: django_site

the stack includes:
File "/home/mattkatz/Projects/django-federation/wellknown/models.py", line 11, in
wellknown.register('host-meta', handler=HostMeta(), content_type='application/xrd+xml')
File "/home/mattkatz/Projects/django-federation/wellknown/resources.py", line 16, in init
hosts = getattr(settings, "WELLKNOWN_HOSTMETA_HOSTS", (Site.objects.get_current().domain,))

commenting out
from resources import HostMeta
register('host-meta', handler=HostMeta(), content_type='application/xrd+xml')

fixes this error

commenting out
for res in Resource.objects.all():
wellknown.register(res.path, content=res.content, content_type=res.content_type)
fixes the following error when running syncdb:
django.db.utils.DatabaseError: no such table: wellknown_resource

django 1.2 python 2.6

@mattkatz
Copy link
Author

So I've done a little more investigating.
It seems that you can get this code to run by adding it to management.py file in a post_syncdb hook.

I got the code in there, but am seeing nothing at http://127.0.0.1:8000/.wellknown/host-meta/

@mattkatz
Copy link
Author

oh dur.
Still getting a 404 and nothing in /.well-known/host-meta/

@paulosman
Copy link
Contributor

Add django.contrib.sites to your INSTALLED_APPS to fix the first problem. That's a documentation bug I think.

For the second problem, what's that code supposed to do? From what I can see, it registers resources that are in the database at the time that models.py is imported, which doesn't seem particularly useful, especially given the save_handler function. This would make a post syncdb signal handler useless, as no resources would exist in the database (unless you wanted to create some in the same post syncdb signal handler).

I think you could just safely delete those two lines.

@kategray
Copy link

kategray commented Nov 9, 2012

There are issues with attempting to save to the database before the tables are created.

I have a fork that avoids the issue - it has a signal that's sent in the view, so none of the initialization code is called unless a well-known url is requested. It completely avoids this issue.

https://github.com/kategray/django-wellknown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants