소스 검색

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

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

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,
title VARCHAR(200) NOT NULL,
price INT,
@@ -135,6 +136,8 @@ insert into guestbook values (NULL, "Hello World");

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

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

/*
Create default database user
*/


+ 2
- 2
src/app/models/database.py 파일 보기

@@ -3,7 +3,7 @@ import mysql.connector
db = mysql.connector.connect(
user='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'
)

+ 1
- 1
src/app/models/project.py 파일 보기

@@ -119,7 +119,7 @@ def set_task(projectid, task_title, task_description, budget):
:type budget: str
"""
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 + "\", \"" +
task_description + "\", \"" + budget + "\", \"waiting for delivery\")")
cursor.execute(query)


불러오는 중...
취소
저장