Cannot drop column needed in a foreign key constraint

Multi tool use
Executing SQL script in server
ERROR: Error 1829: Cannot drop column 'cod_Cliente': needed in a foreign key constraint 'fk_Cuotas_Clientes1' of table 'gimnasio.cuotas'
ALTER TABLE `Gimnasio`.`Clientes` DROP COLUMN `Observación` ,
DROP COLUMN `Cedula` , DROP COLUMN `cod_Cliente` ,
CHANGE COLUMN `FechaDeNacimiento` `FechaDeNacimiento` INT(11) NULL DEFAULT NULL,
CHANGE COLUMN `Dirección` `Dirección` VARCHAR(100) NULL DEFAULT NULL ,
ADD COLUMN `cod_Cliente` INT(11) NOT NULL FIRST ,
ADD COLUMN `Cédula` INT(11) NULL DEFAULT NULL AFTER `Apellido` ,
ADD COLUMN `Observación` VARCHAR(150) NULL DEFAULT NULL AFTER `Telefono` ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`cod_Cliente`)
SQL script execution finished: statements: 12 succeeded, 1 failed
java mysql database-connection
add a comment |
Executing SQL script in server
ERROR: Error 1829: Cannot drop column 'cod_Cliente': needed in a foreign key constraint 'fk_Cuotas_Clientes1' of table 'gimnasio.cuotas'
ALTER TABLE `Gimnasio`.`Clientes` DROP COLUMN `Observación` ,
DROP COLUMN `Cedula` , DROP COLUMN `cod_Cliente` ,
CHANGE COLUMN `FechaDeNacimiento` `FechaDeNacimiento` INT(11) NULL DEFAULT NULL,
CHANGE COLUMN `Dirección` `Dirección` VARCHAR(100) NULL DEFAULT NULL ,
ADD COLUMN `cod_Cliente` INT(11) NOT NULL FIRST ,
ADD COLUMN `Cédula` INT(11) NULL DEFAULT NULL AFTER `Apellido` ,
ADD COLUMN `Observación` VARCHAR(150) NULL DEFAULT NULL AFTER `Telefono` ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`cod_Cliente`)
SQL script execution finished: statements: 12 succeeded, 1 failed
java mysql database-connection
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21
add a comment |
Executing SQL script in server
ERROR: Error 1829: Cannot drop column 'cod_Cliente': needed in a foreign key constraint 'fk_Cuotas_Clientes1' of table 'gimnasio.cuotas'
ALTER TABLE `Gimnasio`.`Clientes` DROP COLUMN `Observación` ,
DROP COLUMN `Cedula` , DROP COLUMN `cod_Cliente` ,
CHANGE COLUMN `FechaDeNacimiento` `FechaDeNacimiento` INT(11) NULL DEFAULT NULL,
CHANGE COLUMN `Dirección` `Dirección` VARCHAR(100) NULL DEFAULT NULL ,
ADD COLUMN `cod_Cliente` INT(11) NOT NULL FIRST ,
ADD COLUMN `Cédula` INT(11) NULL DEFAULT NULL AFTER `Apellido` ,
ADD COLUMN `Observación` VARCHAR(150) NULL DEFAULT NULL AFTER `Telefono` ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`cod_Cliente`)
SQL script execution finished: statements: 12 succeeded, 1 failed
java mysql database-connection
Executing SQL script in server
ERROR: Error 1829: Cannot drop column 'cod_Cliente': needed in a foreign key constraint 'fk_Cuotas_Clientes1' of table 'gimnasio.cuotas'
ALTER TABLE `Gimnasio`.`Clientes` DROP COLUMN `Observación` ,
DROP COLUMN `Cedula` , DROP COLUMN `cod_Cliente` ,
CHANGE COLUMN `FechaDeNacimiento` `FechaDeNacimiento` INT(11) NULL DEFAULT NULL,
CHANGE COLUMN `Dirección` `Dirección` VARCHAR(100) NULL DEFAULT NULL ,
ADD COLUMN `cod_Cliente` INT(11) NOT NULL FIRST ,
ADD COLUMN `Cédula` INT(11) NULL DEFAULT NULL AFTER `Apellido` ,
ADD COLUMN `Observación` VARCHAR(150) NULL DEFAULT NULL AFTER `Telefono` ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`cod_Cliente`)
SQL script execution finished: statements: 12 succeeded, 1 failed
java mysql database-connection
java mysql database-connection
edited Jul 12 '17 at 6:30
Luciano van der Veekens
4,77541626
4,77541626
asked Jul 11 '17 at 21:18


Alberto FleitasAlberto Fleitas
1
1
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21
add a comment |
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21
add a comment |
1 Answer
1
active
oldest
votes
Remove the foreign key before modifying a primary key field:
ALTER TABLE gimnasio.cuotas
DROP FOREIGN KEY fk_Cuotas_Clientes1
After that, do your ALTER TABLE
.
And finally, do not forget to create again the relationship:
ALTER TABLE gimansio.cuotas ADD CONSTRAINT fk_Cuotas_Clientes1 FOREIGN KEY (col_name) REFERENCES gimnasio.Clientes(cod_Cliente);
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replacecol_name
with the column name of your tablecuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45044629%2fcannot-drop-column-needed-in-a-foreign-key-constraint%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Remove the foreign key before modifying a primary key field:
ALTER TABLE gimnasio.cuotas
DROP FOREIGN KEY fk_Cuotas_Clientes1
After that, do your ALTER TABLE
.
And finally, do not forget to create again the relationship:
ALTER TABLE gimansio.cuotas ADD CONSTRAINT fk_Cuotas_Clientes1 FOREIGN KEY (col_name) REFERENCES gimnasio.Clientes(cod_Cliente);
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replacecol_name
with the column name of your tablecuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
add a comment |
Remove the foreign key before modifying a primary key field:
ALTER TABLE gimnasio.cuotas
DROP FOREIGN KEY fk_Cuotas_Clientes1
After that, do your ALTER TABLE
.
And finally, do not forget to create again the relationship:
ALTER TABLE gimansio.cuotas ADD CONSTRAINT fk_Cuotas_Clientes1 FOREIGN KEY (col_name) REFERENCES gimnasio.Clientes(cod_Cliente);
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replacecol_name
with the column name of your tablecuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
add a comment |
Remove the foreign key before modifying a primary key field:
ALTER TABLE gimnasio.cuotas
DROP FOREIGN KEY fk_Cuotas_Clientes1
After that, do your ALTER TABLE
.
And finally, do not forget to create again the relationship:
ALTER TABLE gimansio.cuotas ADD CONSTRAINT fk_Cuotas_Clientes1 FOREIGN KEY (col_name) REFERENCES gimnasio.Clientes(cod_Cliente);
Remove the foreign key before modifying a primary key field:
ALTER TABLE gimnasio.cuotas
DROP FOREIGN KEY fk_Cuotas_Clientes1
After that, do your ALTER TABLE
.
And finally, do not forget to create again the relationship:
ALTER TABLE gimansio.cuotas ADD CONSTRAINT fk_Cuotas_Clientes1 FOREIGN KEY (col_name) REFERENCES gimnasio.Clientes(cod_Cliente);
edited Jul 11 '17 at 21:31
answered Jul 11 '17 at 21:24


Oscar MartinezOscar Martinez
4321515
4321515
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replacecol_name
with the column name of your tablecuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
add a comment |
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replacecol_name
with the column name of your tablecuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
Where do i put this code?
– Alberto Fleitas
Jul 11 '17 at 21:47
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
I am sorry, but i am new in this
– Alberto Fleitas
Jul 11 '17 at 21:48
The first block before your instruction. And the ending block after your instruction. (Replace
col_name
with the column name of your table cuotas
– Oscar Martinez
Jul 11 '17 at 21:49
The first block before your instruction. And the ending block after your instruction. (Replace
col_name
with the column name of your table cuotas
– Oscar Martinez
Jul 11 '17 at 21:49
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
Do not forget to accept this as answer if it solved your problem.
– Oscar Martinez
Jul 11 '17 at 22:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45044629%2fcannot-drop-column-needed-in-a-foreign-key-constraint%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
G4V VXS1 SOf,A,T77rjvBc RweKhMUWeCkg,pNpi5u7nH03r6oXyzI7v1UQvbESf gJ3Puaj bSl9zq8E2lwyxomku
Drop the foreign key constraint before dropping the column?
– Joe C
Jul 11 '17 at 21:20
Also, please do not tag languages that have nothing to do with the question.
– Joe C
Jul 11 '17 at 21:21