backup1-technicise / Django-Sample

Few projects and CRUD operations using Django (1.11.2), Django Piston and Python 2.7
MIT License
1 stars 0 forks source link

Modify some settings under project's settings.py #4

Open backup1-technicise opened 7 years ago

backup1-technicise commented 7 years ago

To enable causes of error during execution

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Add our app emp_CRUD and Djangorestframework into our Django project

# Application definition
INSTALLED_APPS = [
    # Uncomment the next line to enable the admin:
    #'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'rest_framework', # Inclusion of Djangorestframework for REST API
    #'emp_CRUD',  # For Django <= 1.9
    'emp_CRUD.apps.EmpCrudConfig' # Inclusion of APP for Django > 1.9
]
backup1-technicise commented 7 years ago

Allow Django to access our MySQL DB as employee_DB

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
'''
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
'''
### Settings for MySQL Database assigned by Abhisek
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'employee_DB',
        'USER': 'root',
        'PASSWORD': 'curatehealth',
        'HOST': 'localhost',
        'PORT': '',
    }
}
backup1-technicise commented 7 years ago

Test Django whether it support above changes or not

(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ python manage.py runserver

I got following error

(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7f1adb1daf50>
Traceback (most recent call last):
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 250, in raise_last_exception
    six.reraise(*_exception)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/models/base.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/models/base.py", line 331, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/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 "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/Django-1.11.3-py2.7.egg/django/db/backends/mysql/base.py", line 30, in <module>
    'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb.
Did you install mysqlclient or MySQL-python?

As remedy I followed some steps as follows:

(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ pip install mysqlclient
Collecting mysqlclient
/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading mysqlclient-1.3.10.tar.gz (82kB)
    100% |████████████████████████████████| 92kB 196kB/s 
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... done
  Stored in directory: /home/user/.cache/pip/wheels/32/50/86/c7be3383279812efb2378c7b393567569a8ab1307c75d40c5a
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.10
/home/user/code/Django-Sample/django_venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

Test Django further

(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 11 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

July 03, 2017 - 10:50:47
Django version 1.11.3, using settings 'django_CRUD_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[03/Jul/2017 10:52:16] "GET / HTTP/1.1" 200 1716

11 unapplied migration(s) are solved by following way

(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ python manage.py migrate
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
    HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying sessions.0001_initial... OK
(django_venv) user@user-VirtualBox:~/code/Django-Sample/django_venv/django_CRUD_project$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
July 03, 2017 - 11:10:07
Django version 1.11.3, using settings 'django_CRUD_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.