I have created a Django application.Now i am trying to populate some data into SQL database tabel EmployeeDetails, using normal python script. But i am not able to insert data into db. I guess its because my db is not connecting with this external python script. I am new with Python, so please help me to solve this.This is my python script :
import MySQLdb
db=MySQLdb.connect("localhost","root","password123","employee")
def dumpdata():
userName = 'John'
designation = 'Software Engineer'
employeeID = '2312'
contactNumber = '9495321257'
project = 'cricket'
dateOfJoin = '2009-10-10'
EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save()
My settings.py in Django is :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'employee', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'password123', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
My final need is to put the insertion code in a loop and populate as many data i need into db. Somebody please look into my code and help me to solve this.