Why am I not being able to insert values into my SQL database?

Gabriel Pulga

I'm working on a school project in which we create three tables and insert a few values onto them using MYSQL Workbench.

Pretty simple stuff right? Here are the tables that are being created :

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Regiao` (
  `codRegiao` BIGINT NOT NULL,
  `nomeRegiao` VARCHAR(100) NOT NULL,
  `descricaoRegiao` TEXT NULL,
  PRIMARY KEY (`codRegiao`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `mydb`.`Vinicola` (
  `codVinicola` BIGINT NOT NULL,
  `nomeVinicola` VARCHAR(100) NOT NULL,
  `descricaoVinicola` TEXT NULL,
  `foneVinicola` VARCHAR(15) NULL,
  `emailVinicola` VARCHAR(15) NULL,
  `codRegiao` BIGINT NOT NULL,
  PRIMARY KEY (`codVinicola`),
  INDEX `fk_Vinicola_Regiao1_idx` (`codRegiao` ASC) VISIBLE,
  CONSTRAINT `fk_Vinicola_Regiao1`
    FOREIGN KEY (`codRegiao`)
    REFERENCES `mydb`.`Regiao` (`codRegiao`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `mydb`.`Vinho` (
  `codVinho` BIGINT NOT NULL,
  `nomeVinho` VARCHAR(50) NOT NULL,
  `tipoVinho` VARCHAR(30) NOT NULL,
  `anoVinho` INT NOT NULL,
  `descricaoVinho` TEXT NULL,
  `codVinicola` BIGINT NOT NULL,
  PRIMARY KEY (`codVinho`),
  INDEX `fk_Vinho_Vinicola_idx` (`codVinicola` ASC) VISIBLE,
  CONSTRAINT `fk_Vinho_Vinicola`
    FOREIGN KEY (`codVinicola`)
    REFERENCES `mydb`.`Vinicola` (`codVinicola`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

And here is the script in which I'm trying to build to insert values onto the tables :

insert into `mydb`.`Regiao` values (1, "Campos Alegres", "Lindos campos verdes");
insert into `mydb`.`Regiao` values (2, "Campos Tristes", "Campos cinzas e planos");
insert into `mydb`.`Regiao` values (3, "Planalto Central", "Campos verdes e montanhosos");
insert into `mydb`.`Regiao` values (4, "Montanhas Roxas", "Terrenos montanhosos e rochosos");
insert into `mydb`.`Regiao` values (5, "Caverna do Dragão", "Temperatura amena e úmida");

insert into `mydb`.`Vinicola` values (1, "Durigan" , "Vinhos para te deixar alegre", "12345678901", "[email protected]" , 1);
insert into `mydb`.`Vinicola` values (2, "Legado" , "Vinhos para te deixar triste", "45623572901", "[email protected]" , 2);
insert into `mydb`.`Vinicola` values (3, "Franco" , "Vinhos para subir nas alturas", "918273531", "[email protected]" , 3);
insert into `mydb`.`Vinicola` values (4, "Bento" , "Vinhos afrodisíacos", "9102184629", "[email protected]" , 4);
insert into `mydb`.`Vinicola` values (5, "Busato" , "Vinhos do centro da terra", "9182736409", "[email protected]" , 5);

insert into `mydb`.`Vinho` values (1, "Manacá", "Merlot", 1998, "Sabor seco e doce", 1);
insert into `mydb`.`Vinho` values (2, "Tupinambá", "Cabernet Sauvignon", 2011, "Sabor suave e doce", 2);
insert into `mydb`.`Vinho` values (3, "Xavassa", "Pinot Noir", 1972, "Vinho tinto e seco", 3);
insert into `mydb`.`Vinho` values (4, "Tiluriloca", "Syrah", 2010, "Vinho rosé", 4);
insert into `mydb`.`Vinho` values (5, "Lapolipo", "Malbec", 2021, "Vinho branco", 5);

The issue is that it's not working, for some reason "Vinho" and "Vinicola" are getting none of the values, showing only NULL columns.

I'm thinking this could have something to do with the relationship keys but I haven't been able to figure it out.

Would be grateful if someone could help me with this.

gview

Your issue is in the definition of the Vinicola.emailVinicola column

 VARCHAR(15) NULL

Your email addresses are larger than 15 characters so the inserts fail, which then causes the Vinho table inserts to fail due to the constraint.

Increase the size of the column to something appropriate like VARCHAR(80)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why am I not able to run my SQL file from command line?

Why am I not able to insert elements into my linked-list implementation?

Why am I not being able to compile SASS with Webpack?

Why I am not able to refer to my sequence with double quotes in postgres?

Why am i not able to push files into My Git Repo

I am not able to insert values into temporary table in a postgres function

Why am I not being able to write into objects I fetched from database?

Why I am not able to receive data in my adapter

Why i am not able to change the dummy variable here in my code?

I'am not able to delete information from my database

Why am I able to instantiate my Abstract Base Class in Python?

Why am I not being able to connect to my database?

Why am I not being able to tar /opt and move it to my USB location in Linux

Why am I not able to fetch database field values in a class using Jooq's into method?

Why I'm not being able to submit my data to my database using JQuery and PHP and why my page keeps redirecting to the home page?

Why i am not able to call adapter method from my activity

Why am I not able to submit my data to database using PHP and MySQL?

Why am I not able to get proper dates in my graph?

Why am I not able to use promise in my basic react app?

Why am I not able oneHot encode my data labels?

I am trying to import my database values, but the results are not being displayed, even though the table structure is correct

Why am I not able to pickup items in my text based game?

I am not able to style my input values as 'chips'

Why am I getting a cross-reference error with my insert/select statement in single database

Why am I not able to set cookies on my device?

Can someone explain me why I am not able to check special characters in my string using ASCII values?

Why am I not able to select data properties from dropdown values?

Why am I not able to access the REST API exposed by my service?

I am unable to figure out why data is not being added to my database with my JS code