0

I tried create these tables:

$sql = "CREATE TABLE IF NOT EXISTS Articls (
            id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,     
            name VARCHAR(254) COLLATE utf8_persian_ci NOT NULL      
) DEFAULT COLLATE utf8_persian_ci";



$sql = "CREATE TABLE IF NOT EXISTS Tags (
            id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,  
            id_articls INT(10) UNSIGNED NOT NULL,   
            name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,           
            FOREIGN KEY (`Tags.id_articls`) REFERENCES Articls(`Articls.id`)
) DEFAULT COLLATE utf8_persian_ci"

;

First table create successfully but secnond I get this error:

Error creating table: Key column 'Tags.id_articls' doesn't exist in table

If I remove Tags. in Tags.id_articls and Tags.id_articls I get errno: 150

Also If I try

   $sql = "CREATE TABLE IF NOT EXISTS Tags (
                id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,  
                id_articls INT(10) UNSIGNED NOT NULL,   
                name VARCHAR(256) COLLATE utf8_persian_ci NOT NULL,           
                FOREIGN KEY (Tags.id_articls) REFERENCES Articls(Articls.id)
    ) DEFAULT COLLATE utf8_persian_ci"

I get this error:

Error creating table: 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 '.id_articls) REFERENCES Articls(Articls.id) ) DEFAULT COLLATE utf8_persian_ci' at line 5

ali raha
  • 211
  • 1
  • 2
  • 14

1 Answers1

1

The foreign key in your Tags table should be id_articls and not Tags.id_articls