MySQLWorkbench forward engineering error - mysql

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!

Related

Importing a database script into my database throws an #1064 error

could you please help me? I bought a domain just for learning databases etc. and I created my model of a database in MySQL Workbench. I generated a script and tried importing it into my database using phpMyAdmin. This is the script:
CREATE TABLE IF NOT EXISTS `knight` (
`idKnight` INT NOT NULL AUTO_INCREMENT,
`strength` INT NOT NULL DEFAULT 1,
`agility` INT NOT NULL DEFAULT 1,
`vitality` INT NOT NULL DEFAULT 1,
`attack` INT GENERATED ALWAYS AS (agility*strength) STORED,
`defense` INT GENERATED ALWAYS AS (vitality*strength) STORED,
`idUser` INT NOT NULL,
`idTavern` INT NULL,
PRIMARY KEY (`idKnight`),
INDEX `fk_user_idx` (`idUser` ASC),
INDEX `fk_tavern_idx` (`idTavern` ASC),
CONSTRAINT `fk_user` FOREIGN KEY (`idUser`)
REFERENCES `user` (`idUser`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_tavern` FOREIGN KEY (`idTavern`)
REFERENCES `tavern` (`idTavern`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
And this is the 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 'GENERATED ALWAYS AS (agility*strength) STORED,
defense INT GENERATED ALWAYS ' at line 6
Now the question is how do I synchronize the MySQL Workbench version of a database for which the script is generated, and the database itself. The database is Inno DB.
Thanks for your help
EDIT: MySQL version of my server is: 5.6.28
This type of problem shows the importance of using the same version of database in development as you will eventually use when you deploy to your production server. So you don't get surprised by incompatibilities.
You can run that script against your MySQL 5.6 server only if you avoid SQL features introduced in more recent versions of MySQL. This includes generated columns, which were first introduced in MySQL 5.7.
So you need to remove these columns, or else change them to plain INT columns, without the generated option.
`attack` INT GENERATED ALWAYS AS (agility*strength) STORED,
`defense` INT GENERATED ALWAYS AS (vitality*strength) STORED,
If you need those columns in query result sets, you have a few alternative solutions:
Add them as expressions in the select-list of a SELECT query:
SELECT (agility*strength) AS `attack`, (vitality*strength) AS `defense`
FROM `knight` ...
Or you could create a VIEW to encode a query with those expressions.
Or you could add those columns as plain integers, and write TRIGGERs on INSERT and UPDATE to keep them in sync with the other columns.
MySQL 5.6.28 was released in December 2015, and the whole 5.6 branch is past its end-of-support date. That means if any security bugs are discovered from now on, they won't be fixed. Besides, you're already using an outdated release of 5.6, with many bugs. The last 5.6 release was 5.6.51 in January 2021.

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.

Problem with making a database on base of EER

I want to make a database based on my EER, but if I use Forward Engineering it always throws the same error.
Executing SQL script in server:
> ERROR: 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 ') ENGINE = InnoDB' at line 8
SQL Code:
-- Table `gip`.`Groepen`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gip`.`Groepen` (
`idGroepen` INT NOT NULL,
`Groepnaam` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idGroepen`),
UNIQUE INDEX `Groepnaam_UNIQUE` (`Groepnaam` ASC) VISIBLE)
ENGINE = InnoDB
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Any idea how to fix this?
I think VISIBLE is added after MySQL server version > 8.0 and you are using less than that.
Moreover, according to https://bugs.mysql.com/bug.php?id=92269, VISIBLE is default value. You can remove it.

MySQL Workbench 1064 error in syntax

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.

MySQL Timestamping

I have a table in an Amazon Web Service (AWS) Relation Database Service (RDS) and the table columns are "Memory", "Cores", "Speed" and "Insert_Timestamp" and I am trying to get the database to log each time a new row is added to this table. With this being said, I am running the following code Alter table Instace_Types ALTER COLUMN Insert_Timestamp SET DEFAULT CURRENT_TIMESTAMP. I am running into this 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 'COLUMN Insert_Timestamp SET DEFAULT CURRENT_TIMESTAMP' at line 1"
any input would be greatly appreciated.
The second ALTER should be a CHANGE.
Alter table Instance_Types
CHANGE Insert_Timestamp
Insert_Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP