Setup python & django with mysql database commands in window
1. Install virtualenv and activate it :
-------------------------------------------------------------------------------------------------------------------
pip install virtualenv
--------------------------------------------------------------------------------------------------------------------
env_name\Scripts\activate
---------------------------------------------------------------------------------------------------------------------
[Note: If error occurred in activating environment then go to the created environment
directory and give command as:]
Set-executionpolicy remotesigned
----------------------------------------------------------------------------------------------------------------------
2. Create django application and mysqlclient
----------------------------------------------------------------------------------------------------------------------
django-admin startproject project_name
----------------------------------------------------------------------------------------------------------------------
pip install mysqlclient
----------------------------------------------------------------------------------------------------------------------
[Note: if error occurred in installing mysqlclient then follow below steps:]
IF ERROR OCCURED.
a. Check the python version and also check the whether python is 32-bit or 64-b then Download the file from:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Choose carefully ---According to python version There is a step given to choose it.
cp38 means for python 3.8 version and cp 37 means for python 3.6 version so first check your python version wether it is 3.8,3.7,3.6,3.5,3.4 then download accordingly.
amd64--- while checking python version also check whether your python is of 64-bit or 32-bit. then select accordingly. If your python is of 32-bit then select amd32.
b. After that goto the path where that file has been downloaded.
Then hit the command as:
pip install mysqlclient-1.4.6-cp37-cp37m-win32.whl
c. Then your Error will be solved
---------------------------------------------------------------------------------------------------------------------
3. Change in settings.py
---------------------------------------------------------------------------------------------------------------------
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': db_name,
'HOST': 'localhost',
'PORT': '3306',
'USER': 'db_username',
'PASSWORD': 'db_password',
}
}
--------------------------------------------------------------------------------------------------------------------
4. Create database table
---------------------------------------------------------------------------------------------------------------------
python manage.py migrate
---------------------------------------------------------------------------------------------------------------------
python manage.py makemigrations
----------------------------------------------------------------------------------------------------------------------
Note: Xampp should be open while migrating and database should also be created
while using xampp..
-------------------------------------------------------------** THE END **--------------------------------------
0 Comments