I have a django project that I am trying to deploy on GAE. However, When I add
from rocket_engine import on_appengine
in my settings.py file, my project starts crashing with this error message:
$ python manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/koray/Dropbox/code/python/taxiweb/wtx/settings.py", line 65, in <module>
from rocket_engine import on_appengine
File "/Library/Python/2.7/site-packages/rocket_engine/__init__.py", line 91, in <module>
setup_appendine_sdk()
File "/Library/Python/2.7/site-packages/rocket_engine/__init__.py", line 56, in setup_appendine_sdk
sys.path.extend(dev_appserver.GOOGLE_SQL_EXTRA_PATHS)
AttributeError: 'module' object has no attribute 'GOOGLE_SQL_EXTRA_PATHS'
The change I have made in the settings file is
if on_appengine:
ROOT_URLCONF = 'urls'
DATABASES = {
'default': {
'ENGINE': 'rocket_engine.db.backends.cloudsql',
'INSTANCE': 'instance:name',
'NAME': 'database_name',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
I am on a mac, django-rocket-engine is installed via pip. What am I missing here?
Related
Trying to migrate a legacy SQLite database (database.sqlite) in Django to inspect_db and pull model information from datbase.sqlite. python manage.py makemigrations seems to be okay but when running python manage.py migrate there's an error.
AttributeError: 'NoneType' object has no attribute 'startswith'
Tried to trackback error but got lost in all the code.
Django==3.2.5
python== 3.7.9
Running migrations:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 246, in handle
fake_initial=fake_initial,
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 91, in migrate
self.recorder.ensure_schema()
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 68, in ensure_schema
editor.create_model(self.Migration)
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/db/backends/sqlite3/schema.py", line 35, in __exit__
self.connection.check_constraints()
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 347, in check_constraints
self.ops.quote_name(primary_key_column_name),
File "/Users/cp/Documents/dsi/django_project/django_env/lib/python3.7/site-packages/django/db/backends/sqlite3/operations.py", line 171, in quote_name
if name.startswith('"') and name.endswith('"'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Here is settings.py database info(commented out other database for troubleshooting purposes.. commented out db.sqlite3 works fine):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'database.sqlite',
}
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
}
In settings file, I have given SQL SERVER Database connection values like this.
DATABASES = {
'default': {
'NAME': 'AdventureWorks2014',
'ENGINE': 'sqlserver_ado',
'HOST': '127.0.0.1',
'USER': '',
'PASSWORD': '',
}
}
Versions:
Django v:1.11
Python v:2.7
django-mssql v:1.8
pip v:9.0
Development Platform:
Visual Studio
After the database connection values changes, I have used the command
python manage.py makemigrations
Here I got the error:
Executing manage.py makemigrations
Traceback (most recent call last):
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\manage.py", line 17, in
execute_from_command_line(sys.argv)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\core\management__init__.py", line 364, in execute_from_command_line
utility.execute()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\core\management__init__.py", line 338, in execute
django.setup()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib__init__.py", line 37, in import_module
import(name)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\contrib\auth\models.py", line 4, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\contrib\auth\base_user.py", line 52, in
class AbstractBaseUser(models.Model):
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\base.py", line 124, in new
new_class.add_to_class('_meta', Options(meta, app_label))
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db__init__.py", line 33, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\utils.py", line 212, in getitem
conn = backend.DatabaseWrapper(db, alias)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\sqlserver_ado\base.py", line 184, in init
super(DatabaseWrapper, self).init(*args, **kwargs)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\backends\base\base.py", line 96, in init
self.client = self.client_class(self)
TypeError: Error when calling the metaclass bases
'NoneType' object is not callable
The interactive Python process has exited.
Can anyone help me solve this?
I am trying to run tests in django which are placed in tests folder.Following is the output.
python manage.py test
Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management __init__.py", line 272, in fetch_command klass = load_command_class(app_name,subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 75, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py",line 40, in import_module __import__(name)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands __init__.py", line 10, in <module> import django.template.loaders.app_directories
File "/usr/local/lib/python2.7/dist-packages/django/template/loaders /app_directories.py", line 23, in <module> mod = import_module(app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module __import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 6, in <module> from django.contrib.admin.sites import AdminSite, site
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py", line 4, in <module> from django.contrib.admin.forms import AdminAuthenticationForm
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/forms.py", line 6, in <module> from django.contrib.auth.forms import AuthenticationForm
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/forms.py", line 17, in <module> from django.contrib.auth.models import User
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 48, in <module> class Permission(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 96, in __new__new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 264, in add_to_class value.contribute_to_class(cls, name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 124, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 196, in __getitem__self.ensure_defaults(alias)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 174, in ensure_defaults conn.setdefault('ATOMIC_REQUESTS', False)
AttributeError: 'tuple' object has no attribute 'setdefault'
Can some one help me with this ?
I have tried solving by checking the enviornment and i think its correct.Tests run good in production with same enviornment.
Database Settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2'
'NAME': 'projectx',
'USER': 'xyz',
'PASSWORD': 'xyz',
'HOST': '127.0.0.1',
'PORT': '',
}
}
if 'test' in sys.argv:
DATABASES['default'] = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test_project',
'USER': 'xyz',
'PASSWORD': 'xyz',
'HOST': '127.0.0.1',
'PORT': '',
},
You have a stray comma after the end of your test DATABASES dict, which turns it into a single-item tuple. Remove that final comma.
I'm trying to build an application with server code on AWS EC2 and the Spatial DB Postgis on RDS. I can access the Postgres from EC2 using command line:
psql --host=mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com --port=5432 --username=ec2 --password --dbname=mydb
mydb=>
I use GeoDjango on the EC2, and this is the setting for my DB:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'ec2',
'PASSWORD': 'password',
'HOST': 'mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com',
'PORT': '5432',
}
}
But when I run migration, it gives my error like this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/usr/lib/python2.6/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/usr/lib/python2.6/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 5, in <module>
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 8, in <module>
from django.contrib.gis.geometry.backend import Geometry
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/__init__.py", line 8, in <module>
module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/geos.py", line 1, in <module>
from django.contrib.gis.geos import (
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/__init__.py", line 7, in <module>
from .libgeos import geos_version, geos_version_info, GEOS_PREPARE
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/libgeos.py", line 58, in <module>
lgeos = CDLL(lib_path)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libgeos_c.so.1: cannot open shared object file: No such file or directory
It looks like I'm missing some libraries of postgis on my EC2. My question is, do I need to install a postgis instance on my ec2 so that my server can find all that necessary libs? Or how can I make my server to look for the libs on the RDS?
Thanks very much!
It looks like you're just missing the "geos" library. If you're running Amazon Linux, installing that is as simple as yum install geos. That library provides the file: /usr/lib/libgeos_c.so.1
I am trying to follow the walkthrough on the django website and I downloaded sqlite and saved it in C:\Windows\System32 folder. When I edit the settings.py file what do I put for the Name field? Do I have to set up a database? The django literature say's that the API should take care of that for sqlite. When I run python manage.py syncdb I just get a bunch of errors. What am I doing wrong?
Jason & Casey#SUPERBEAST ~/Desktop/mysite
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
252, in fetch_command
app_name = get_commands()[subcommand]
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
101, in get_commands
apps = settings.INSTALLED_APPS
File "c:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set
up
self._wrapped = Settings(settings_module)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 93, in __in
it__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
}
^
SyntaxError: invalid syntax
I haven't tried django under windows but python 2.7 surely comes with sqlite out of the box.
How to setup the database?
on the top of the file:
import os
then:
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
}
}
and finally a syncdb should do the trick.
If it doesn't work, mind to paste the traceback?
The problem is:
File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
}
^
SyntaxError: invalid syntax
Check the syntax a paren or brace hasn't been closed properly around DATABASES.