Spaces:
Sleeping
Sleeping
Update database/models.py
Browse files- database/models.py +9 -10
database/models.py
CHANGED
@@ -3,19 +3,20 @@ from datetime import datetime
|
|
3 |
import mysql.connector
|
4 |
from config import Config
|
5 |
|
6 |
-
|
7 |
def create_tables():
|
|
|
8 |
conn = mysql.connector.connect(
|
9 |
-
host=
|
10 |
-
|
11 |
-
|
12 |
-
password='your_password', # make sure this is your actual MySQL root password
|
13 |
-
database='ragchatbot',
|
14 |
-
auth_plugin='mysql_native_password' # explicitly specify auth method
|
15 |
)
|
16 |
-
|
17 |
cursor = conn.cursor()
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
cursor.execute('''
|
20 |
CREATE TABLE IF NOT EXISTS chat_messages (
|
21 |
id INT AUTO_INCREMENT PRIMARY KEY,
|
@@ -28,5 +29,3 @@ def create_tables():
|
|
28 |
conn.commit()
|
29 |
cursor.close()
|
30 |
conn.close()
|
31 |
-
|
32 |
-
|
|
|
3 |
import mysql.connector
|
4 |
from config import Config
|
5 |
|
|
|
6 |
def create_tables():
|
7 |
+
# First, create the database if it doesn't exist
|
8 |
conn = mysql.connector.connect(
|
9 |
+
host=Config.MYSQL_HOST,
|
10 |
+
user=Config.MYSQL_USER,
|
11 |
+
password=Config.MYSQL_PASSWORD
|
|
|
|
|
|
|
12 |
)
|
|
|
13 |
cursor = conn.cursor()
|
14 |
|
15 |
+
# Create database if it doesn't exist
|
16 |
+
cursor.execute(f"CREATE DATABASE IF NOT EXISTS {Config.MYSQL_DB}")
|
17 |
+
cursor.execute(f"USE {Config.MYSQL_DB}")
|
18 |
+
|
19 |
+
# Create table
|
20 |
cursor.execute('''
|
21 |
CREATE TABLE IF NOT EXISTS chat_messages (
|
22 |
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
29 |
conn.commit()
|
30 |
cursor.close()
|
31 |
conn.close()
|
|
|
|