I am trying to create a database that is going to be used in my airport management system. Currently, I have a Seats table that has a seat number and a reference to Flight through a flight number. I also have a Customer table with basic information and identified by the Passport No. The SQL looks like this:
CREATE TABLE IF NOT EXISTS `seats` ( `Seat_no` int(3) NOT NULL, `flight_no` int(5) NOT NULL, PRIMARY KEY (`Seat_no`,`flight_no`), KEY `Seat_no` (`Seat_no`), KEY `flight_no` (`flight_no`), CONSTRAINT `seats_ibfk_1` FOREIGN KEY (`flight_no`) REFERENCES `flights` (`Flight_No`) ON DELETE CASCADE ON UPDATE CASCADE )
All you really have to know is the Seats primary key is the set of Seat_no and Flight_no, as multiple flights can have the same seat number. The primary key of the Flight is the flight_no and the primary key of the customer is Passport_no. I want to make a table, called Booked, that essentially holds Passport_no, Seat_no, Flight_no, where Passport_no is a reference to a customer, and Seat_no, Flight_no is a reference to the Seat. But doing something like this isn't working:
CREATE TABLE IF NOT EXISTS `booked` ( `Passport_No` int(8) NOT NULL, `Seat_No` int(3) NOT NULL, `Flight_no` int(5) NOT NULL, PRIMARY KEY (`Passport_No`,`Seat_No`,`Flight_no`), UNIQUE KEY `Seat_No` (`Seat_No`,`Flight_no`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ALTER TABLE `booked` ADD CONSTRAINT `fk_constraint` FOREIGN KEY (`Seat_No`, `Flight_no`) REFERENCES `seats` (`Seat_no`, `flight_no`), ADD CONSTRAINT `booked_ibfk_1` FOREIGN KEY (`Passport_No`) REFERENCES `customers` (`Passport_No`) ON DELETE CASCADE;
Keep in mind, I am using the phpMyAdmin interface to create these tables and such, and the booked table gets created, but when I try to insert some data using the interface I get an error stating that my constraints were broken. Is it possible to have a FK that is of 2 columns?
submitted by steezpak
Need Help with setting up a project with PHP and Drupal and MySQL with Wamp Server and Windows Subsystem for Linux
Hello everyone I got this project where I have to setup the PHP project which also has this Drupal framework thing so that I can further more do the front-end development with it.
- I have first tried the WAMP server and I was able to put my project in the /vawww/html and then I have this myasghelp.sql file given which I set up in the phpMyAdmin, but it gives out an error
( you can see the pic in this link : https://media.discordapp.net/attachments/308736623661547520/506000234615275520/unknown.png?width=750&height=378
SET FOREIGN_KEY_CHECKS = ON;
so I tried to find it in the sql file ( i opened it in VSCode ) but I couldn't find that line)
I installed UniServer
but it also didn't work because it only allows me to upload a sql file of only 12MiB
(yeah that's an i
between M and B), where as my SQL file is 155MB
Since I have the Windows SubSystem for Linux I have followed this article : https://medium.com/@fiqriismail/how-to-setup-apache-mysql-and-php-in-linux-subsystem-for-windows-10-e03e67afe6ee
to set up Apache, PHP, MySql-server in the bash shell, but and then again in the mysql-server I ran the files create database myasghelp;
and then in the bash the following command:
sudo mysql -u root -p myasghelp < myasghelp.sql
so that I can migrate the whole tables from that sql files to my current database for the projects
sudo mysql -u root -p myasghelp < myasghelp.sql Enter password: ERROR at line 240001: Unknown command '\a'.
so I'm stuck with it, and also there are only 1912 lines in my sql file. I also tried to check it by running following
head -n 10 myasghelp.sql
but it only shows this:
``` -- phpMyAdmin SQL Dump -- version 4.7.4
-- Host: 127.0.0.1:3306 -- Generation Time: Oct 17, 2018 at 06:40 AM -- Server version: 5.7.19 -- PHP Version: 5.6.31
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; ```
and when I go to my sql file and find the line; it says no results found
- and then also setup the project path so that apache server can figure it out by following command
sudo ln -s /mnt/b/work/myasghelp /vawww/html/clientproject
so now whenever I go to localhost/clientproject in my browser it does run the project but since the project has this insatll.php which starts showing me how to install the Drupal along with it, and what frustrates me is that it can't recognise that there already a database that I have configured and instead it asks me to setup a new DB and id and password for it.
Any guidance/help/advice will help me so much, and if you guys want I can share the database .sql file as well if you want it. Do you think I should give XAMPP a try ?
submitted by tapu_buoy