Missing Value in form when creating a table in phpmyadmin SQL - mysql

I am trying to make a table but every time I type my sql code I get an error "Missing value in form". I am sure there is no problem with the code rather something else.
Here is my code
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Related

Error code: 1824 Failed to open the refernced table [table exists]

I'm trying to add a foreign key constraint, but I'm getting [Error Code: 1824: Failed to open the refrenced table 'agent_agent']
the table agent_agent exists in my database, I can't get my head around this issue.
I tried creating the constraint using the graphical mode of mysql workbench and I'm getting the same error.
select * from agent_agent; return the data, so the table exists in the DB but:
ALTER TABLE demande_contact
ADD CONSTRAINT dddd
FOREIGN KEY (agent_id_id) REFERENCES agent_agent(id);
is returning an error 1824.
Edit: Here's the 2 tables DDL
CREATE TABLE `agent_agent` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`matricule` varchar(6) NOT NULL,
`nom_et_prenom` varchar(60) NOT NULL,
`fonction` varchar(60) NOT NULL,
`structure` varchar(60) NOT NULL,
`poste_org` varchar(60) DEFAULT NULL,
`metier` varchar(3) DEFAULT NULL,
`csp` varchar(20) DEFAULT NULL,
`en_activite` tinyint(1) NOT NULL,
`timestamp` datetime(6) NOT NULL,
`updated` datetime(6) NOT NULL,
`user_id` int(11) NOT NULL,
`service` varchar(60) DEFAULT NULL,
`centre_cout` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `agent_agent_user_id_bfcb5c50` (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=628 DEFAULT CHARSET=utf8
CREATE TABLE `demande_contact` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`telephone` varchar(40) NOT NULL,
`agent_id_id` int(11) NOT NULL,
`demande_id_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `demande_contact_demande_id_id_0abc00b0_fk_demande_d` (`demande_id_id`),
KEY `agent_id_id_constraint_idx` (`agent_id_id`),
CONSTRAINT `demande_contact_demande_id_id_0abc00b0_fk_demande_d` FOREIGN KEY (`demande_id_id`) REFERENCES `demande_demandetransport` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Change table structure from mysql to sqllite

i want to change database of my simple application from mysql to sqlite, this is my sql command :
CREATE TABLE `Todo` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
im try to create sqllite but return me this error : Error: near "AUTO_INCREMENT": syntax error how i can fix it ?
Instead of using primary key separately, please mention it with your AUTO INCREMENT key
CREATE TABLE `Todo` (
`Id` integer primary key AUTOINCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL
)

mysql refference key issue, phpmyadmin error code 150 [duplicate]

This question already has answers here:
MySQL Creating tables with Foreign Keys giving errno: 150
(20 answers)
Closed 7 years ago.
I am trying to create two table as below,
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `Id` int(11) NOT NULL
AUTO_INCREMENT, `UserType` varchar(32) DEFAULT NULL, `FirstName`
varchar(64) DEFAULT NULL, `LastName` varchar(64) DEFAULT NULL,
`Email` varchar(64) DEFAULT NULL, `CompanyName` varchar(64) DEFAULT
NULL, `Telephone` varchar(64) DEFAULT NULL, `Country` varchar(64)
DEFAULT NULL, `Website` varchar(64) DEFAULT NULL, `JobTitle`
varchar(64) DEFAULT NULL, `Active` int(1) DEFAULT NULL, `Notes`
text, `DateOfRegistration` datetime DEFAULT NULL, PRIMARY KEY
(`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Table structure for table `login`
--
CREATE TABLE IF NOT EXISTS `login` ( `Id` int(11) NOT NULL,
`Username` varchar(64) NOT NULL, `Email` varchar(64) NOT NULL,
`Password` varchar(64) NOT NULL, `FailedAttemptCount` int(2) NOT
NULL, `LastLogin` datetime NOT NULL, `UserLevel` int(1) NOT NULL,
`IsVerified` int(1) NOT NULL DEFAULT '0', `VerificationKey`
varchar(256) NOT NULL, `VerifiKeyCreated` datetime NOT NULL,
PRIMARY KEY (`Id`), FOREIGN KEY (`Id`) REFERENCES users.Id, UNIQUE
KEY `username` (`Username`), UNIQUE KEY `Email` (`Email`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1;
I want to add a foreign key i.e. login.Id references users.Id, but I am getting error(code 150) in phpmyadmin.
Thanks in advance for your help!
Best Regards,
Rajib
It should be
REFERENCES `users`(`Id`)
instead of
REFERENCES users.Id
cf. http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

MySQL Error Number 150 when creating Table with Foreign Key

I am having an issue creating a new table in my database. I've seen that the error code it is returning is to do with Foreign Key constraints.
I checked to ensure that the data type of the foreign key in the new table matched the data type of the primary key in the other table. They are both int(11).
However I am still getting an error. Am I missing something? This is my SQL script for creating the new table:
CREATE TABLE `regular_features` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(200) DEFAULT NULL,
`day` VARCHAR(200) DEFAULT NULL,
`description` TEXT DEFAULT NULL,
`programme_id` INT(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`programme_id`) REFERENCES directoryprogramme(id)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
This is the original table containing the primary key:
CREATE TABLE `directoryprogramme` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(250) NOT NULL,
`broadcast_time` VARCHAR(100) NOT NULL,
`description` TEXT NOT NULL,
`days` VARCHAR(150) NOT NULL,
`contributors` VARCHAR(250) NOT NULL,
`directorycompany_id` INT(11) NOT NULL,
`directorycontact_id` VARCHAR(250) NOT NULL,
`facebook_link` VARCHAR(250) DEFAULT NULL,
`twitter_link` VARCHAR(250) DEFAULT NULL,
`wikipedia_link` VARCHAR(250) DEFAULT NULL,
`web` VARCHAR(250) DEFAULT NULL,
`imageextension` VARCHAR(10) DEFAULT NULL,
`type` VARCHAR(20) NOT NULL DEFAULT 'other',
PRIMARY KEY (`id`)
) ENGINE=MYISAM AUTO_INCREMENT=1161 DEFAULT CHARSET=utf8;
The Foreign Key will be the id of directoryprogramme
The problem is the last line of your create statement:
ENGINE=INNODB DEFAULT CHARSET=utf8;
You mix MYISAM in ald table with INNODB in your new table.
That doesn't work.
Chnage the engine in your new table to MYISAM and it works.

Delete Cascade Multiple Tables

I wonder whether someone can help me please.
I have the following three tables:
Parent Table
CREATE TABLE `userdetails` (
`userid` int(6) NOT NULL auto_increment,
`forename` varchar(20) NOT NULL,
`surname` varchar(30) NOT NULL,
`emailaddress` varchar(150) NOT NULL,
`password` varchar(200) NOT NULL,
`passwordhint` varchar(20) NOT NULL,
`subscriptionexpiration` date NOT NULL,
`salt` varchar(200) NOT NULL,
PRIMARY KEY (`userid`),
UNIQUE KEY `emailaddress` (`emailaddress`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Child Table
CREATE TABLE `detectinglocations` (
`userid` int(6) NOT NULL,
`locationid` int(6) NOT NULL auto_increment,
`locationname` varchar(80) NOT NULL,
`address` varchar(110) NOT NULL,
`osgb36lat` float(10,6) NOT NULL,
`osgb36lon` float(10,6) NOT NULL,
`osgridref` varchar(20) NOT NULL,
`wgs84latd` int(2) NOT NULL,
`wgs84latm` int(2) NOT NULL,
`wgs84lats` decimal(6,2) NOT NULL,
`wgs84latb` varchar(1) NOT NULL,
`wgs84lond` int(2) NOT NULL,
`wgs84lonm` int(2) NOT NULL,
`wgs84lons` decimal(6,2) NOT NULL,
`wgs84lonb` varchar(1) NOT NULL,
`nameoflocationcontact` varchar(30) NOT NULL,
`locationcontactsaddressline1` varchar(50) NOT NULL,
`locationcontactsaddressline2` varchar(50) default NULL,
`locationcontactsaddressline3` varchar(50) default NULL,
`locationcontactsaddressline4` varchar(50) default NULL,
`locationcontactstelephonenumber` varchar(15) default NULL,
PRIMARY KEY (`locationid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Child Table
CREATE TABLE `detectors` (
`userid` int(6) NOT NULL,
`detectorid` int(6) NOT NULL auto_increment,
`detectorname` varchar(30) NOT NULL,
PRIMARY KEY (`detectorid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=1 ;
Using the this code below, I'm trying to implement the 'Delete Cascade' functionality, whereby if the user is deleted from the parent table, the associated rows within the child tables are alse deleted.
ALTER TABLE 'tablename'
add CONSTRAINT fk_userdetails
FOREIGN KEY (userid)
REFERENCES userdetails(userid)
ON DELETE CASCADE
I can successfully implement this for the first child table, but when I try to do the same with the second child table I receive the following error:
#1005 - Can't create table './db369054642/#sql-30d_bd1a57.frm' (errno: 121)
I've done quite a bit of research to find out what the problem may be, but I must admit I'm none the wiser.
Could someone perhaps have a look at this please and let me know what I'm doing wrong?
Many thanks
The solution is on http://dev.mysql.com/doc/refman/5.0/en/innodb-error-codes.html in the post by Mark Robbins on September 29 2007 10:19pm and the next one:
Constraint names must be unique
fk_userdetails is not unique
So you might try
ALTER TABLE 'tablename'
add CONSTRAINT fk_userdetails_detectors
FOREIGN KEY (userid)
REFERENCES userdetails(userid)
ON DELETE CASCADE
on the second table