Currently , I have deployed my django project on google app engine. I need to run python manage.py migrate
command so that auth_user
table should be created on my google cloud instance . But don't know where to run this command.
目前,我已经在谷歌app engine上部署了django项目。我需要运行python管理。py迁移命令,以便在我的谷歌云实例上创建auth_user表。但是不知道在哪里运行这个命令。
1 个解决方案
#1
8
If I get it right, your app runs on App Engine (sandboxed environment) and uses Cloud SQL.
如果我猜对了,你的应用程序运行在应用引擎(沙箱环境)上,并使用云SQL。
1) Configure your database in settings.py
as you can see below.
1)在设置中配置数据库。就像你在下面看到的。
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/project-id:instance-name',
'NAME': 'database-name',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': 'cloud-sql-instance-ip-address',
'NAME': 'database-name',
'USER': 'root',
'PASSWORD': 'password',
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database-name',
'USER': 'username',
'PASSWORD': 'password',
}
}
2) Set environment variable SETTINGS_MODE to prod (or do not set if you want to access your local MySQL server).
2)将环境变量SETTINGS_MODE设置为prod(如果您想访问本地MySQL服务器,请不要设置)。
3) Run the below command from your machine.
从你的机器上运行下面的命令。
$ SETTINGS_MODE=prod python manage.py migrate
You can find more details in App Engine documentation - Management commands and Alternate development database and settings.
您可以在App Engine文档中找到更多细节—管理命令和备用开发数据库和设置。
#1
8
If I get it right, your app runs on App Engine (sandboxed environment) and uses Cloud SQL.
如果我猜对了,你的应用程序运行在应用引擎(沙箱环境)上,并使用云SQL。
1) Configure your database in settings.py
as you can see below.
1)在设置中配置数据库。就像你在下面看到的。
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/project-id:instance-name',
'NAME': 'database-name',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': 'cloud-sql-instance-ip-address',
'NAME': 'database-name',
'USER': 'root',
'PASSWORD': 'password',
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database-name',
'USER': 'username',
'PASSWORD': 'password',
}
}
2) Set environment variable SETTINGS_MODE to prod (or do not set if you want to access your local MySQL server).
2)将环境变量SETTINGS_MODE设置为prod(如果您想访问本地MySQL服务器,请不要设置)。
3) Run the below command from your machine.
从你的机器上运行下面的命令。
$ SETTINGS_MODE=prod python manage.py migrate
You can find more details in App Engine documentation - Management commands and Alternate development database and settings.
您可以在App Engine文档中找到更多细节—管理命令和备用开发数据库和设置。