浏览代码

Workaround adding a task to NO TEAM at id 1 to satisfy foreignt key even to the task is not assigned

https
jakobsn 6 年前
父节点
当前提交
89bc30aaa6
共有 3 个文件被更改,包括 9 次插入6 次删除
  1. +6
    -3
      mysql/sql/init.sql
  2. +2
    -2
      src/app/models/database.py
  3. +1
    -1
      src/app/models/project.py

+ 6
- 3
mysql/sql/init.sql 查看文件

@@ -25,7 +25,7 @@ CREATE TABLE guestbook (
*/ */


CREATE TABLE teams ( CREATE TABLE teams (
teamid INT UNSIGNED AUTO_INCREMENT,
teamid INT AUTO_INCREMENT,
team_name VARCHAR(200) NOT NULL, team_name VARCHAR(200) NOT NULL,
write_permission BOOLEAN, write_permission BOOLEAN,
PRIMARY KEY (teamid) PRIMARY KEY (teamid)
@@ -79,7 +79,7 @@ CREATE TABLE projects_users (
CREATE TABLE tasks ( CREATE TABLE tasks (
taskid INT UNSIGNED AUTO_INCREMENT, taskid INT UNSIGNED AUTO_INCREMENT,
projectid INT UNSIGNED NOT NULL, projectid INT UNSIGNED NOT NULL,
teamid INT UNSIGNED NULL,
teamid INT,
title VARCHAR(200) NOT NULL, title VARCHAR(200) NOT NULL,
task_description VARCHAR(500), task_description VARCHAR(500),
budget INT NOT NULL, budget INT NOT NULL,
@@ -87,6 +87,7 @@ CREATE TABLE tasks (
feedback VARCHAR(500) NULL, feedback VARCHAR(500) NULL,
PRIMARY KEY (taskid), PRIMARY KEY (taskid),
FOREIGN KEY (teamid) REFERENCES teams(teamid) FOREIGN KEY (teamid) REFERENCES teams(teamid)
FOREIGN KEY (projectid) REFERENCES projects(projectid)
); );


CREATE TABLE task_files ( CREATE TABLE task_files (
@@ -114,7 +115,7 @@ CREATE TABLE delivery (
); );


CREATE TABLE task_offer ( CREATE TABLE task_offer (
offerid INT UNSIGNED AUTO_INCREMENT,
offerid INT UNSIGNED AUTO_INCREMENT,1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`db`.`tasks`, CONSTRAINT `tasks_ibfk_1` FOREIGN KEY (`teamid`) REFERENCES `teams` (`teamid`))
taskid INT UNSIGNED NOT NULL, taskid INT UNSIGNED NOT NULL,
title VARCHAR(200) NOT NULL, title VARCHAR(200) NOT NULL,
price INT, price INT,
@@ -135,6 +136,8 @@ insert into guestbook values (NULL, "Hello World");


insert into project_category values (NULL, "Test"); insert into project_category values (NULL, "Test");


insert into teams values (0, "NO TEAM", FALSE);

/* /*
Create default database user Create default database user
*/ */


+ 2
- 2
src/app/models/database.py 查看文件

@@ -3,7 +3,7 @@ import mysql.connector
db = mysql.connector.connect( db = mysql.connector.connect(
user='root', user='root',
password='root', password='root',
#host='10.5.0.5', # Docker address
host='0.0.0.0', # Local address
host='10.5.0.5', # Docker address
#host='0.0.0.0', # Local address
database='db' database='db'
) )

+ 1
- 1
src/app/models/project.py 查看文件

@@ -119,7 +119,7 @@ def set_task(projectid, task_title, task_description, budget):
:type budget: str :type budget: str
""" """
cursor = db.cursor() cursor = db.cursor()
query = ("INSERT INTO tasks (projectid, title, task_description, budget, task_status) VALUES (\"" +
query = ("INSERT INTO tasks (teamid, projectid, title, task_description, budget, task_status) VALUES (1, \"" +
projectid + "\", \"" + task_title + "\", \"" + projectid + "\", \"" + task_title + "\", \"" +
task_description + "\", \"" + budget + "\", \"waiting for delivery\")") task_description + "\", \"" + budget + "\", \"waiting for delivery\")")
cursor.execute(query) cursor.execute(query)


正在加载...
取消
保存