1

I have my report dashboard that I'm developing using Django and I want to connect it to my MySQL database without using models.py or migrations.

Basically, here's what I've done so far.

views.py

import configparser

config = configparser.ConfigParser()
config.read('db.ini')


def getConnection():
    host = config['ord']['host']
    port = config['ord']['port']
    database = config['ord']['database']
    password = config['ord']['password']
    user = config['ord']['user']
    
    connection = pymssql.connect(host=host, user=user, password=password, database=database)
    cursor = connection.cursor()
    print("Connection Succesfull")
    
    return cursor

def fill_weight(request):
    try:
        sql = u """
            SELECT * FROM fill_weight;
        """
        sql =sql.encode('utf-8')
        cursor.execute(sql)
        cursor.fetchall()

db.ini

[oof_ord]
host = localhost
port = 3306
database = xxxxxxxxxxx
user = xxxxxxxxxxx
password = xxxxxxxxxxx
default-character-set = utf8

The reason why I want to do this is because I don't have the official database that I'm going to use for this system and I want to easily access it by putting it's database credentials to my db.ini and access it to show the data without doing any migrations. Is there anyone that can help me ?

5
  • you mean something like Database First ORM? Commented Oct 13, 2020 at 16:48
  • in your case Flask as micro framework would be the option that fits your needs. Commented Oct 13, 2020 at 16:53
  • @EbrahimKarimi Yes sir something like that. Commented Oct 13, 2020 at 16:55
  • @cizario Yah but the client requries me to use django for this Commented Oct 13, 2020 at 16:55
  • ok check this out hope it helps Commented Oct 13, 2020 at 17:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.