Migrating MySQL to SQLite for Django Site - python

(Migrate may not be the correct term I'm unsure) I'm trying to figure out how to change my Django site to register SQLite. Originally SQLite is the default for Django however I changed to MySQL because the original site I was going to host on (GoDaddy) was compatible with it. The only solution I thought of so far is changing the DATABASES info in my Settings.py. After changing my Settings to the defaults of
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
I ran into this error,
(env) PS C:\Users\kayak\New Work\google athentication\mysite> python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\kayak\New Work\google athentication\mysite\manage.py", line 22, in <module>
main()
File "C:\Users\kayak\New Work\google athentication\mysite\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\core\management\__init__.py", line 386, in execute
settings.INSTALLED_APPS
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 92, in __getattr__
self._setup(name)
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\kayak\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\kayak\New Work\google athentication\mysite\mysite\settings.py", line 12, in <module>
import heroku
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\__init__.py", line 27, in <module>
from .core import from_key, get_key, from_pass
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\core.py", line 10, in <module>
from .api import Heroku
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\api.py", line 11, in <module>
from .helpers import is_collection
File "C:\Users\kayak\New Work\google athentication\env\lib\site-packages\heroku\helpers.py", line 57
except TypeError, e:
^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized
Thanks for any incite and or help in advance!

Related

Django deploy to Heroku No module named 'django_heroku'

I'm tryin to deploy to Heroku and before this error I was getting:
ModuleNotFoundError: No module named 'django-tables2'
Then I installed django-heroku via pip install django-heroku, followed the instructions on how to set it up.
I disabled the collect static for heroku pushed my master branch and everything is fine, but once I do:
heroku run python manage.py migrate
I get the:
ModuleNotFoundError: No module named 'django_heroku'
the complete traceback is this:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute()
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 341, in run_from_argv
connections.close_all()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 225, in close_all
for alias in self:
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 219, in __iter__
return iter(self.databases)
File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 153, in databases
self._databases = settings.DATABASES
File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/GPC/settings.py", line 14, in <module>
import django_heroku
ModuleNotFoundError: No module named 'django_heroku'
I have in my settings at the top:
import os
import django_heroku
and in the very bottom:
django_heroku.settings(locals())
in my requirements.txt I have django-heroku
The master branch is updated and I just can find how to fix this.
The problem was that it was not added to the module, it was needed to be added to the virtual env and then do the pip freeze, with that it was solved.

Why Django tries to use MySQL instead of sqlite3

My problem is this: When I try to do the migrations, it gives me the following error:
python3 manage.py makemigrations
Traceback (most recent call last):
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/jenifer/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/jenifer/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/jenifer/.local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/jenifer/.local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/jenifer/.local/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/jenifer/.local/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/jenifer/.local/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/models/base.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/models/base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/models/options.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/utils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/jenifer/.local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 21, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Thing is, I've never told django to use MySQL, in fact, the settings.py states that it has to use SQLite:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'gestlote.db'),
}
}
I've alreay tried to reinstall django, upgrade it, pip3 install pysqlite, but nothing seems to work.
So please, help me

ImportError: cannot import name 'memoize' when doing python3 manage.py migrate

I have an issue with migration in Django using python3 manage.py migrate it shows me about memoize
I have installed django-memoize and included it on my settings.py but it still shows the error.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/contrib/admin/apps.py", line 24, in ready
self.module.autodiscover()
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/mycomputer/.local/lib/python3.6/site-packages/adminsortable/admin.py", line 15, in <module>
from django.shortcuts import render
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/shortcuts/__init__.py", line 14, in <module>
from django.core import urlresolvers
File "/home/mycomputer/.local/lib/python3.6/site-packages/django/core/urlresolvers.py", line 19, in <module>
from django.utils.functional import memoize, lazy
ImportError: cannot import name 'memoize'
It should have migrated after installation of memoize.
Thank you for all the support I need to install some dependencies and re-install my python then after that I created a virtual environment and install dependencies.

How Prepare the database for SALEOR

Prepare the database for SALEOR:
$ python manage.py migrate
This command will need to be able to create database extensions. If you get an error related to the CREATE EXTENSION command please review the notes from the user creation step.
# python3 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 216, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 12, in <module>
from django.db.migrations.autodetector import MigrationAutodetector
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/autodetector.py", line 11, in <module>
from django.db.migrations.questioner import MigrationQuestioner
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/questioner.py", line 9, in <module>
from .loader import MigrationLoader
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/loader.py", line 8, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder:
File "/usr/local/lib/python3.5/dist-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Help me for this ERROR, Please.
Setting SECRET_KEY solved this for me.
$ export SECRET_KEY='secret key output'
One way to generate a secret key:
$ python3
>>> import random
>>> ''.join(random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!##$%^&*(-_=+)') for i in range(50))
'some secret key output appears here'
>>>

Python 3.5.2 error UndefinedValueError

My application is configured for use mysql, but when i try to run ./manage.py migrate this error ocours
root#renato-VirtualBox:/home/renato/unb-alerta# ./manage.py migrate
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/django/core/management/__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/renato/unb-alerta/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/renato/unb- alerta/venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/renato/unb-alerta/unb_alerta/settings.py", line 139, in <module>
cast=db_url,
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/decouple.py", line 197, in __call__
return self.config(*args, **kwargs)
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/decouple.py", line 77, in __call__
return self.get(*args, **kwargs)
File "/home/renato/unb-alerta/venv/lib/python3.5/site- packages/decouple.py", line 64, in get
raise UndefinedValueError('%s option not found and default value was not defined.' % option)
decouple.UndefinedValueError: DATABASE_URL option not found and default value was not defined.
My .env have DATABASE_URL end my settings.py has this configuration
DATABASES = {
'default': config(
'DATABASE_URL',
cast=db_url,
)
}

Categories

Resources