使用SQLITE进行Google App Engine的本地Django开发吗? [英] Using SQLITE for local Django development for Google App Engine?

查看:75
本文介绍了使用SQLITE进行Google App Engine的本地Django开发吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine在Django中进行开发。对于生产,我计划使用Google Cloud SQL,但对于本地开发,我想使用简单的SQLITE。 Google教程( https://developers.google.com/appengine/docs / python / cloud-sql / django )建议我运行开发服务器,

I am doing development in Django with Google App Engine. For production I plan to use Google Cloud SQL but for local development I want to use the simple SQLITE. The Google Tutorial (https://developers.google.com/appengine/docs/python/cloud-sql/django) suggests that I run the development server with

dev_appserver.py mysite

而不是Django默认值

instead of the Django default

manage.py runserver

但是,当我以Google身份运行开发服务器时建议我遇到两个奇怪的错误(为清楚起见,我删除了堆栈跟踪的其余部分):

However, when I run the development server as Google suggested I get two strange errors (I removed the rest of the stack trace for clarity):

File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django1.5/django/db/backends/sqlite3/base.py", line 34, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3


File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py", line 53, in load_middleware
raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e)) ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "cannot import name utils"

最奇怪的部分是,当我只使用manage.py runserver时,站点运行正常。同样,当我在交互式python提示符下直接测试sqlite3时,它也可以正常工作:

The strangest part is that when I just use manage.py runserver the site works fine. Also when I tested directly in the interactive python prompt for sqlite3 it also works:

Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> 

这里有人可以帮助我吗?我不确定下一步该怎么做。

Can anyone here help me? I'm not sure what to do next. Thanks in advance!

推荐答案

我偶然发现了同一块石头,直到我意识到GAE至少不允许您使用SQLite。

I stumbled on the same stone until I realized that GAE does not allow you to use SQLite, at least not right out-of-the-box...

因此,他们的开发服务器不允许这样做,以防止在部署时出现任何意外情况。

Therefore their development server does not allow it neither in order to prevent any bad surprise at deployment time.

事件虽然可能有一种方法,因为Google Appengine文档有时会引用某些 SQlite Stub,但我无法安全地浏览其文档丛林,并且发现最近没有像样的,工作示例。

Eventhough there might be a way because the Google Appengine docs sometimes refer to some "SQlite Stub", I was not able to navigate safely throughout their doc jungle and found no recent, decent, working example.

因此,到目前为止,一种解决方案是:如果需要关系数据库,请使用mysql,但是一旦推出,则必须付费。 GAE。请注意,定价可能确实很便宜。

So as for now, one solution is: use mysql if you require a relational database, BUT you will have to pay a subscription once you roll it out on GAE. Note that the pricing can be really cheap.

以下是您的settings.py文件的声明示例:

Here is an example declaration for your settings.py file:

if (os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine') or
    os.getenv('SETTINGS_MODE') == 'prod'):
    # Running on production App Engine, so use a Google Cloud SQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'google.appengine.ext.django.backends.rdbms',
            'INSTANCE': '<project>-pts:ptsdb',
            'NAME': '<dbname>',
            'OPTIONS': {"init_command": "SET storage_engine=INNODB"},
        }
    }
else:
    # Running in development, so use a local MySQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '<dbname>',
            'USER': '<username>',
            'PASSWORD': '',
            'HOST': 'localhost',
            'OPTIONS': {"init_command": "SET storage_engine=INNODB"},
        }
    }

否则,您可以也可以免费使用其NDB数据库,但是您将无法在实体之间定义强关系(外键)。

Otherwise you can also use their NDB database for free, BUT you will not be able to define "strong" relationships (foreign keys) between your entities.

这篇关于使用SQLITE进行Google App Engine的本地Django开发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆