1
./manage.py reset app1
를 실행할 때 다음과 같은 오류가 발생합니다.Django에서 OneToOneField가 다른 응용 프로그램을 통과하여 데이터베이스 재설정
Error: Error: app1 couldn't be reset. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset app2'. That's the SQL this command wasn't able to run.
The full error: (1217, 'Cannot delete or update a parent row: a foreign key constraint fails')
OneToOneField가 다른 모델의 다른 모델 (app2)에있는 모델입니다. 나는 MySQL InnoDB를 사용하고있다. 보다 정확하게, OneToOneField는 app2 모델에서 선언됩니다.
이 오류를 제거하려면 어떻게합니까?
업데이트 :(app1)
BEGIN;
DROP TABLE `app1_instance`;
DROP TABLE `app1_instancegroup`;
CREATE TABLE `app1_instancegroup` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
-- some more fields
)
;
CREATE TABLE `app1_instance` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`belongs_to_id` integer NOT NULL,
-- some more fields
)
;
ALTER TABLE `app1_instance` ADD CONSTRAINT `belongs_to_id_refs_id_455b868f` FOREIGN KEY (`belongs_to_id`) REFERENCES `app1_instancegroup` (`id`);
CREATE INDEX `app1_instance_belongs_to_id` ON `app1_instance` (`belongs_to_id`);
COMMIT;
(app2)
BEGIN;
DROP TABLE `app2_team`;
CREATE TABLE `app2_team` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`instance_group_id` integer NOT NULL UNIQUE,
-- some more fields
)
;
ALTER TABLE `app2_team` ADD CONSTRAINT `instance_group_id_refs_id_39493b52` FOREIGN KEY (`instance_group_id`) REFERENCES `app1_instancegroup` (`id`);
COMMIT;
django-admin.py sqlreset app2의 출력을 살펴 보았습니까? 그게 뭐야? –
업데이트했습니다. – Achimnol
MySQL 콘솔을 통해 외래 키 제약 조건을 수동으로 삭제해야했습니다. Django에서 이러한 종류의 작업에 대한 지원이 있습니까? – Achimnol