Django MongoDB引擎运行tellsiteid时出错
所以我按照教程创建了一个 django 项目和应用程序,并且我拥有 MongoDB 引擎所需的所有依赖项,在我尝试启用管理界面之前,一切似乎都工作正常。
我取消注释了 require 位,并将“django_mongodb_engine”和“djangotoolbox”添加到 settings.py 中的应用程序部分
当我尝试进入 localhost:8000/admin 时,出现错误:
“AutoField(默认主键)值必须是字符串代表 MongoDB 上的 ObjectId(改为 u'1')。请确保您的 SITE_ID 包含有效的 ObjectId 字符串。”
经过一些谷歌搜索后,显然我必须运行manage.pytellsiteid,它会向我吐出一个可以在settings.py中使用的ID,这将使错误消失,但是当我尝试运行manage.pytellsiteid时,我得到:
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site- packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute()
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 8, in handle_noargs
site_id = self._get_site_id()
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 19, in _get_site_id
return Site.objects.get().id
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get
% self.model._meta.object_name)
django.contrib.sites.models.DoesNotExist: Site matching query does not exist.
SO I created a django project and app as per the tutorial and I have all the dependencies necessarry for MongoDB Engine it all seemed to be working fine and dandy till I tried enabling the admin interface.
I uncommented the require bits, and added 'django_mongodb_engine' and 'djangotoolbox' to the apps section in settings.py
When I try to get into localhost:8000/admin I get an error:
"AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'1' instead). Please make sure your SITE_ID contains a valid ObjectId string."
After some googling apparently I have to run manage.py tellsiteid and it'll spit me an ID I can use within my settings.py that will make the error go away, but when I try to run manage.py tellsiteid I get:
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site- packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute()
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 8, in handle_noargs
site_id = self._get_site_id()
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 19, in _get_site_id
return Site.objects.get().id
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get
% self.model._meta.object_name)
django.contrib.sites.models.DoesNotExist: Site matching query does not exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以创建您的站点,然后获取 id:
然后:
You can create your site, and then, get the id:
and then:
如果您不需要
sites
功能(很有可能),只需关闭django.contrib.sites
应用程序,它将修复与 SITE_ID 相关的 MongoDB 问题:If you do not need the
sites
functionality (which is very probable) simply turn offdjango.contrib.sites
app and it will fix MongoDB issues related to the SITE_ID:您还没有创建任何网站。运行
manage.pysyncdb
来创建一个。You haven't created any Site yet. Run
manage.py syncdb
to create one.你试过这个: http://django-mongodb.org/troubleshooting.html#站点 ID 问题
have you tried this: http://django-mongodb.org/troubleshooting.html#site-id-issues
由于某种原因,这里的解决方案都不适合我。
python ./manage.pytellsiteid
,没有django_site
集合,注释掉'django.contrib.sites'
会导致奇怪的错误。不过,从 shell 中获取 ID 对我有用,详细信息如下:
https://gist.github.com/ ielshareef/2986459
或者在这里站点匹配查询不存在
将其放入
设置中。 py
一切都很好!For some reason none of the solutions here worked for me.
python ./manage.py tellsiteid
, there was nodjango_site
collection, and commenting out'django.contrib.sites'
caused weird errors.Grabbing the ID from the shell worked for me though, detailed here:
https://gist.github.com/ielshareef/2986459
or here Site matching query does not exist
Put it in
settings.py
and everything worked great!前几天我在设置过程中遇到了这个问题。
基本上,您需要登录到 mongo shell 并查找您的 siteid,然后将其添加到您的 settings.py
登录到 mongo shell
选择您的数据库
,然后在 django_site 上执行 find()
然后打开您的 settings.py 并编辑 site_ID ="" 行(我的在下面)
这应该能让你启动并运行
I ran into this during my setup the other day.
Basically you need to logo into a mongo shell and lookup your siteid then add it your settings.py
log into a mongo shell
select your db
then do a find() on django_site
Then open your settings.py and edit the site_ID ="" line (mine is below)
That should get you up and running
您很可能尚未创建站点,为此您需要运行命令
这将创建站点,现在您需要在设置文件中添加其 site_id。获取站点 ID,连接到正在运行的 mongodb 引擎,然后运行以下命令,
得到类似的内容
您将在设置文件中
,然后管理界面应该可以工作。是吗?
Most likely you havent created a site yet, to do so you need to run the command
This creates the site, now you need to add its site_id in your settings file. Go get the site id, connect to mongodb engine that is running, and run the following commands
you will get something like
then in your settings file, put
and the admin interface should work. Does it?
我使用
manage.pysyncdb
然后manage.pytellsiteid
但仍然显示错误。我最终通过删除数据库并再次同步来解决它。
希望这可以帮助别人:)
I use
manage.py syncdb
and thenmanage.py tellsiteid
but still display error.I finally solve it by dropping the database and sync again.
Hope this can help someone:)
sudo python manage.py shell
放入settings.py
SITE_ID = u'53aa6456984edd0d5e547e03'
sudo python manage.py shell
Put it in settings.py
SITE_ID = u'53aa6456984edd0d5e547e03'