How to rename column name foreign key constraint in MySql Query?
In this post we will give you information about How to rename column name foreign key constraint in MySql Query?. Hear we will give you detail about How to rename column name foreign key constraint in MySql Query?And how to use it also give you demo for it if it is necessary.
This is more one post on mysql query, I don’t remember exactly time but i had need to change name of foreign key constraint column field. We can rename field name easily if we didn’t set foreign key constraint. But if you set foreign key constraint then you can’t rename easily. I had rename directly from my phpmyadmin without mysql query but i found bellow error:
PHP - I Can't get the $_POST Values on Ajax Request
In this post we will give you information about PHP - I Can't get the $_POST Values on Ajax Request. Hear we will give you detail about PHP - I Can't get the $_POST Values on Ajax RequestAnd how to use it also give you demo for it if it is necessary.
I want to share this posts with you because when i was working on native PHP and Ajax Post request(Specially AngularJS Post request) at that time i can't get Post value on form submit. That's why i would like to share you this post. I also want to tell you i was working on my Ubuntu 14.04. I did try lot but i can't get value.
At last find stuff to how to solve this issue, i did use "file_get_contents('php://input')" that way i could get POST value in json object and i also decode json value using "json_decode()". So let's try this way :
Example:
$post = file_get_contents('php://input');
$post = json_decode($post);
$sql = "INSERT INTO items (title) VALUES ('".$post->title."')";
$result = $mysqli->query($sql);
Hope this code and post will helped you for implement PHP - I Can't get the $_POST Values on Ajax Request. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
Query error:
#1025 - Error on rename of './learn/#sql-46c_246' to './learn/my_table' (errno: 150)
But i found the solution of mysql rename foreign key constraint using mysql query, First we have to drop the foreign key, then change the column, at last we need to again add the foreign key constraint back in column.
I give you also if you want to create and check what do then first create “my_table” using bellow mysql query and then fire bellow sql query for rename column.
Create Table:
CREATE TABLE my_table (
id int unsigned not null AUTO_INCREMENT key,
name VARCHAR(255) default null,
user_id int unsigned not null,
CONSTRAINT 'my_table_user_id_fk'
FOREIGN KEY (user_id) REFERENCES users (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
Rename Column:
ALTER TABLE 'my_table'
DROP FOREIGN KEY 'my_table_user_id_fk',
CHANGE COLUMN user_id sender_id int unsigned not null,
ADD CONSTRAINT 'my_table_sender_id_fk'
FOREIGN KEY ('sender_id') REFERENCES 'users' ('id')
ON DELETE CASCADE
ON UPDATE CASCADE
Try this it will help you sure…..
Hope this code and post will helped you for implement How to rename column name foreign key constraint in MySql Query?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs