Is there a way to temporarily disable Duplicate entry in phpMyAdmin? - php

I keep on getting the below error message when I try to enter some important records I accentually deleted.
Duplicate entry 'EMIR2023 ' for key 'flightNo'
Is there a way in the phpMyAdmin environment I can disable the UNIQUE KEY then activate it when I am done with inserting the records?
Find below the structure of my table, I hope it helps
--
-- Table structure for table `flightSched`
--
CREATE TABLE IF NOT EXISTS `flightSched` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timePeriod` time DEFAULT '00:00:00',
`depOrArriv` varchar(9) DEFAULT NULL,
`flightNo` varchar(9) NOT NULL,
`airline` varchar(20) DEFAULT NULL,
`dest` varchar(30) DEFAULT NULL,
`origin` varchar(30) DEFAULT NULL,
`depature` time DEFAULT '00:00:00',
`don` set('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') DEFAULT NULL,
`arrivalTime` datetime DEFAULT '0000-00-00 00:00:00',
`arrivalTimeSec` varchar(28) DEFAULT NULL,
`status` varchar(15) NOT NULL,
`image_type` varchar(25) DEFAULT NULL,
`image` blob NOT NULL,
`image_size` varchar(25) DEFAULT NULL,
`image_name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `flightNo` (`flightNo`),
UNIQUE KEY `arrivalTime_2` (`arrivalTime`),
KEY `arrivalTime` (`arrivalTime`),
KEY `arrivalTime_3` (`arrivalTime`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=537 ;
Looking forward to your reply :-)

Try unique_checks
SET unique_checks=0;
... import operation ...
SET unique_checks=1;
check reference

Related

How do i make my database auto-generate unique Certificate number that will also be auto-incremented for example 00001

I am creating a database that will store 'graduate details'. I have been able to set the ID to auto increment, Unique and also my primary key that start from 1...
I also want to make the certificate number field unique and auto-increment value in an increasing order that will start from 00001.
Please any help on how to go about this will be very appreciated. Thank you.
This is the MYSQL code for the database below;
CREATE TABLE IF NOT EXISTS `graduates` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`f_name` varchar(25) NOT NULL,
`l_name` varchar(25) NOT NULL,
`gender` varchar(6) DEFAULT NULL,
`address` varchar(100) DEFAULT NULL,
`city` varchar(15) DEFAULT NULL,
`region` varchar(30) DEFAULT NULL,
`phone` varchar(15) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`certificate_number` int(50) NOT NULL AUTO_INCREMENT,
`programme` varchar(50) CHARACTER SET utf8mb4 NOT NULL,
`marks` int(10) NOT NULL,
`college_name` varchar(50) CHARACTER SET utf8mb4 NOT NULL,
`date_of_birth` date DEFAULT NULL,
`created_by` int(10) UNSIGNED NOT NULL DEFAULT 0,
`created_at` date DEFAULT NULL,
`updated_by` int(10) UNSIGNED NOT NULL DEFAULT 0,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `certificate_number` (`certificate_number`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8;

MySQL server has gone away on geoname allcountriess

i'm tring to add geoname allcountries in my database
after adding some data show MySQL server has gone away
allmost after 37890 rows then show show MySQL server has gone
DROP TABLE IF EXISTS `geo_allcountries`;
CREATE TABLE `geo_allcountries` (
`geonameid` INT(11) NOT NULL,
`name` VARCHAR(200) DEFAULT NULL,
`asciiname` VARCHAR(200) DEFAULT NULL,
`alternatenames` VARCHAR(4000) DEFAULT NULL,
`latitude` DECIMAL(10 , 7 ) DEFAULT NULL,
`longitude` DECIMAL(10 , 7 ) DEFAULT NULL,
`fclass` CHAR(1) DEFAULT NULL,
`fcode` VARCHAR(10) DEFAULT NULL,
`country` VARCHAR(2) DEFAULT NULL,
`cc2` VARCHAR(60) DEFAULT NULL,
`admin1` VARCHAR(20) DEFAULT NULL,
`admin2` VARCHAR(80) DEFAULT NULL,
`admin3` VARCHAR(20) DEFAULT NULL,
`admin4` VARCHAR(20) DEFAULT NULL,
`population` INT(11) DEFAULT NULL,
`elevation` INT(11) DEFAULT NULL,
`gtopo30` INT(11) DEFAULT NULL,
`timezone` VARCHAR(40) DEFAULT NULL,
`moddate` DATE DEFAULT NULL,
PRIMARY KEY (`geonameid`),
KEY `name` (`name`),
KEY `asciiname` (`asciiname`),
KEY `latitude` (`latitude`),
KEY `longitude` (`longitude`),
KEY `fclass` (`fclass`),
KEY `fcode` (`fcode`),
KEY `country` (`country`),
KEY `cc2` (`cc2`),
KEY `admin1` (`admin1`),
KEY `population` (`population`),
KEY `elevation` (`elevation`),
KEY `timezone` (`timezone`)
) ENGINE=MYISAM DEFAULT CHARSET=UTF8 COLLATE UTF8_UNICODE_CI;
ALTER TABLE `geo_allcountries` DISABLE KEYS;
LOAD DATA LOCAL INFILE 'D:/allCountries.txt'
INTO TABLE `geo_allcountries`
CHARACTER SET 'UTF8';
ALTER TABLE `geo_allcountries`
ADD COLUMN `fclasscode` CHAR(7) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL AFTER `fcode`;
UPDATE `geo_allcountries`
SET
`fclasscode` = CONCAT(`fclass`, '.', `fcode`);
UPDATE `geo_allcountries`
SET `fclasscode` = ''
WHERE
`fclasscode` NOT REGEXP '[A-Z]{1}.[A-Z]{1,5}';
ALTER TABLE `geo_allcountries` ADD INDEX `fclasscode` (`fclasscode` ASC);
ALTER TABLE `geo_allcountries` ENABLE KEYS;
add this line have the same error
SET FOREIGN_KEY_CHECKS = ON;
php config
max_allowed_packet = 2048M
$cfg['ExecTimeLimit'] =0;
with this same error
$cfg['ExecTimeLimit'] =3000;
post_max_size=1800M
upload_max_filesize=2048M
max_execution_time=2048
max_input_time=1700M
memory_limit=1048M
file size of geoname allcountries.txt file is 1.38GB
how to solve this and where is a problem
I spend much time on this issue but i'm unable to slove
please find out and how to solve this

#1215 - Cannot add foreign key constraint

I'm working a project with Yiiframwork and I have this table in my data base project
CREATE TABLE IF NOT EXISTS `tbl_annonce` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`idEntreprise` tinyint(3) unsigned NOT NULL
COMMENT 'CONSTRAINT FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id)',
`titre` varchar(100) NOT NULL,
`detailleDiscription` varchar(5000) NOT NULL,
`categorie` varchar(100) DEFAULT NULL,
`typePoste` varchar(100) NOT NULL,
`salaireMin` varchar(80) NOT NULL,
`salaireMax` varchar(80) NOT NULL,
`niveauEtude` varchar(80) NOT NULL,
`niveauExperience` varchar(80) NOT NULL,
`langue` varchar(50) DEFAULT NULL,
`poste` varchar(50) NOT NULL,
`pays` varchar(50) NOT NULL,
`ville` varchar(50) NOT NULL,
`adresse` varchar(80) NOT NULL,
`datePublication` timestamp NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`etat` varchar(50) NOT NULL,
`photo` varchar(255) NULL,
`nometr` text NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_idEntrepriseAnn`
FOREIGN KEY (idEntreprise)
REFERENCES tbl_entreprise(id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
I only use 'comment' because I found it in a tutorial for a yii framework project.
I have got the attribute 'idEntreprise' as FK in my DB but when I entred other 'idEntreprise' that does note exist in my table entreprise it was not problem, instead it must be a problem.
So I added 'identreprise' as Fk and that have this problem now.
Hope you understand my problem :/
can any one helep me plz !!
To define a foreign key on a column, it must fulfil some conditions.
Child and parent column must have same column definition by type,
signed.
Parent column must have an index defined on it.
Make sure that
The column tbl_entreprise.id is indexed.
The column definition idEntreprise tinyint(3) unsigned in tbl_annonce matches
with that of tbl_entreprise.id
Refer to: MySQL: Foregin Key Constaints

cakephp manual sql query in one table

I have this table structure
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(50) DEFAULT NULL,
`realname` varchar(50) NOT NULL,
`password` varchar(50) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`bos1` varchar(30) DEFAULT NULL,
`emailbos1` varchar(50) DEFAULT NULL,
`role` varchar(20) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
I got an issue here :
Two persons (eg: username=steve, and balmer) has bos1 name (eg: bill)
When I login as steve and/or balmer I can see my own detail / data,
but when I login as bill, I want to show steve's and balmer's detail as well.
How do i suppose to do it ?
Thank you.

Confusing mysql problem

I have got a problem with two tables:
CREATE TABLE IF NOT EXISTS `addresses` (
`adr_id` int(11) NOT NULL auto_increment,
`per_id` int(11) NOT NULL,
`adr_street` varchar(50) NOT NULL,
`adr_houseno` int(11) default NULL,
`adr_housenoadd` varchar(10) default NULL,
`adr_postalcode` varchar(25) NOT NULL,
`adr_city` varchar(20) NOT NULL,
`adr_type` varchar(45) default NULL,
`cnt_id` int(11) NOT NULL,
`adr_date` date default NULL,
`sys-mut-dt` timestamp NULL default NULL,
`sys-mut-user` varchar(20) default NULL,
`sys-mut-id` int(11) NOT NULL default '0',
PRIMARY KEY (`adr_id`),
KEY `per_id` (`per_id`),
KEY `cnt_id` (`cnt_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
--
-- RELATIES VOOR TABEL `addresses`:
-- `cnt_id`
-- `countries` -> `cnt_id`
-- `per_id`
-- `persons` -> `per_id`
--
CREATE TABLE `events` (
`evt_id` int(11) NOT NULL auto_increment,
`evt_name` varchar(50) NOT NULL,
`evt_description` varchar(100) default NULL,
`evt_startdate` date NOT NULL,
`evt_enddate` date default NULL,
`evt_starttime` time default NULL,
`evt_endtime` time default NULL,
`evt_amtpersons` int(11) default NULL,
`sts_id` int(11) NOT NULL,
`adr_id` int(11) default NULL,
`evt_amtPersonsSubs` tinyint(4) NOT NULL default '0',
`evt_photo` varchar(50) default NULL,
`sys-mut-dt` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`sys-mut-user` varchar(20) default NULL,
`sys-mut-id` int(11) NOT NULL default '0',
PRIMARY KEY (`evt_id`),
KEY `sts_id` (`sts_id`),
KEY `adr_id` (`adr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The problem is, when i try to delete a record from address table I get the following error
DELETE
FROM addresses
WHERE per_id = 45
1451 - Cannot delete or update a parent row: a foreign key constraint fails (`site/events`, CONSTRAINT `adr_id` FOREIGN KEY (`adr_id`) REFERENCES `addresses` (`adr_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ;
The weird thing is that there is no record with the same per_id or adr_id in the events table.
So what's going on over here?
How Can I solve this? ;-)
/* I think it means "How can I solve this?" */
It may sound stupid, but are you absolutely sure there are no child rows?
Could you please run this:
SELECT e.*
FROM addresses a
JOIN events e
ON e.adr_id = a.adr_id
WHERE a.per_id = 45

Categories