MySQL Workbench 1064 error in syntax - mysql

MySQL Workbench created this code, not me. I just used the GUI.
Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `isometr1_keyboard`.`records`
ADD CONSTRAINT `fk_records_layout_id`
FOREIGN KEY ()
REFERENCES `isometr1_keyboard`.`layouts` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION;
ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
REFERENCES `isometr1_keyboard`.`layouts` ()
ON DELETE NO ACTION
ON UPDAT' at line 3
SQL Statement:
ALTER TABLE `isometr1_keyboard`.`records`
ADD CONSTRAINT `fk_records_layout_id`
FOREIGN KEY ()
REFERENCES `isometr1_keyboard`.`layouts` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION
I don't understand where the error is. Also don't understand why the GUI is creating code that is buggy.
Did I make a mistake?

The data types of the columns were not matching. This caused MySQL Workbench to create improperly formed code.

Related

Why does MYSQL error when I try to add a foreign key?

I am trying to make a relational database in MYSQL.
Currently, I am making the foreign keys and connecting them to the parent table.
The problem is when I try to do this(in MYSQL workbench) MYSQL adds this line of code:
ADD INDEX `FK_party_coalitionparty_idx` (`partyId` ASC) VISIBLE;
After some research, I found out that it does this because when I delete or update the parent table, it is really handy when the child tables also delete or update the connected values(or columns).
The problem is when I run the foreign key code without the add index line it runs without trouble, but with it added (and I think I understand why it is good to have it added) it errors and does not want to execute the code to update my database.
When I try to execute the code in a SQL file it gives me the following error with the word VISIBLE:
VISIBLE is not valid at this position.
When I only try to delete the visible word, it cannot add my constraint (I think because you cannot put 2 times add below each other). I will include some screenshots and the message log to make my problem more clear.
Message log:
Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `testdatabase`.`coalitionparty`
ADD INDEX `FK_party_coalitionparty_idx` (`partyId` ASC) VISIBLE;
;
ALTER TABLE `testdatabase`.`coalitionparty`
ADD CONSTRAINT `FK_party_coalitionparty`
FOREIGN KEY (`partyId`)
REFERENCES `testdatabase`.`party` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 2
SQL Statement:
ALTER TABLE `testdatabase`.`coalitionparty`
ADD INDEX `FK_party_coalitionparty_idx` (`partyId` ASC) VISIBLE
My SQL File (when I try to run the SQL code but not with the workbench menu:
SQL file with the error included at the bottom
The question:
How do I need to fix this problem, so that I am able to use cascade and I don't get the error?
Thanks in advance!
Mariadb has no VISIBLE
check the manual for more information
So you can only do
ALTER TABLE `coalitionparty`
ADD INDEX `FK_party_coalitionparty_idx` (`partyId` ASC) ;
or switch to MySsQL

You have an error in your SQL syntax; ... 'UNIQUE `UK6i9q4suadww4j167aqe2h6aqj`' at line 4

I am trying to remove Unique constraint from a column using flyway DB migration in spring-boot. But I am not able to figure out the right query for that. Here is my existing query
ALTER TABLE `choices` DROP UNIQUE `UK6i9q4suadww4j167aqe2h6aqj`;
Here is the error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE `UK6i9q4suadww4j167aqe2h6aqj`' at line 4
Note: the above query is working fine if I am running it through PHPMyAdmin. Its ask for confirmation and then remove it.
Use
ALTER TABLE `choices` DROP index `UK6i9q4suadww4j167aqe2h6aqj`;
This will only work , if there in no foreign key defined that references your key.
.
In which case you have to drop the foreign keys first.

MySQLWorkbench forward engineering error

I'm working on a model in MySql Workbench 8.0, when I click on forward engineering and try to generate the script of my model I get
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VISIBLE,
CONSTRAINT `fk_Compras_Personas`
FOREIGN KEY (`persona_id`)
R' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `bd_inventario2018_2`.`compras`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bd_inventario2018_2`.`compras` (
`nmcompra` INT(11) NOT NULL,
`persona_id` INT(11) NOT NULL,
`fecompra` DATE NOT NULL,
PRIMARY KEY (`nmcompra`, `persona_id`),
INDEX `fk_Compras_Personas_idx` (`persona_id` ASC) VISIBLE,
CONSTRAINT `fk_Compras_Personas`
FOREIGN KEY (`persona_id`)
REFERENCES `bd_inventario2018_2`.`personas` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Or when i try to syncronize the model I get
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VISIBLE' at line 4
SQL Code:
ALTER TABLE `bd_inventario2018_2`.`productos`
ADD COLUMN `anchetas_id` INT(11) NOT NULL AFTER `psventa`,
ADD COLUMN `productoscol` VARCHAR(45) NOT NULL AFTER `anchetas_id`,
ADD INDEX `fk_productos_Anchetas1_idx` (`anchetas_id` ASC) VISIBLE
SQL script execution finished: statements: 3 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Someone knows what's happening? This is an automatic process, I'm not overwritting anything,
Thanks
MySQL Workbench is generating the script for MySQL 8 (which supports the new invisible indexes), which you likely do not have.
You need to specify the MySQL version you are using, either in Model\Model Options\MySQL\Target MySQL Version or, globally, in Edit\Preferences\Modelling\MySQL\Target MySQL Version.
Alternatively, you can go on the MySQL Workbench GUI, Edit->Preferences then Modeling->Mysql and change the default target MySQL.
I had the same problem, using version = 8.0.17.
The error originates when a relationship is formed if No action is selected in the "Foreign Key Options" section. Ensure that the Skip in SQL generation is checked (When No action is selected).
This should solve the problem!

Adding foreign key - Error Code 1064

I'm trying to add a foreign key to my table by the following code:
ALTER TABLE scenes ADD CONSTRAINT fk_dancer_charachter FOREIGN KEY (dancer_pick) references characters(character);
But it keeps saying: Error Code 1064: You have an error in your sql syntax: check the manual that corresponds to your MySQL sever version for the right syntax to use near 'charachter)' at line 1.
Why is that? The syntax seems correct! Isn't it? What am I doing wrong?
Thanks
You are using a reserved word - CHARACTER.
More information in Reserved Words in MySQL 5.5

Where do I look for the database script generated from JPA Entities?

I am having a few errors like the following when I deploy my JPA entities into JBoss.
18:34:53,462 ERROR [SchemaExport] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group (id)' at line 1
18:34:53,684 ERROR [SchemaExport] Unsuccessful: alter table Value add index FK4E9A15132C855E3 (groupId), add constraint FK4E9A15132C855E3 foreign key (groupId) references Group (id)
Where do I look for the generated database script to create the tables ?I would like to take a look at it to debug my errors
Thanks.
You can not use Group as a table name. GROUP is a SQL keyword, so we need to rename it.
Do the following
#Entity
#Table(name="GROUPI") // or other name
public class Group {
}
regards,