I create the tables as follows.

CREATE TABLE photo ( photo_id int NOT NULL PRIMARY KEY, photo_url VARCHAR(200) ); CREATE TABLE article ( date int, text VARCHAR(500), photo_id int, FOREIGN KEY (photo_id) REFERENCES photo(photo_id) ) ENGINE=InnoDB; 

When populating the tables in the photo_id column, the fields remain NULL. Why doesn’t auto-complete happen?

  • You did not specify the photo.photo_id property for the photo.photo_id field - Nofate
  • After specifying the AUTO_INCREMENT property of photo.photo_id in the article.photo_id column article.photo_id values ​​are still NULL - Gareev Denis
  • one
    Something is not clear .. do you insert an entry in the photo and expect that something will be added to the article ? And why on earth? - Alexey Shimansky
  • Apparently I did not fully understand the topic of primary and foreign keys. Started learning SQL a week ago. Therefore, I beg your pardon for lame questions. - Gareev Denis
  • one
    No, without explicit reference you cannot. But the database will ensure that the photo_id values ​​in the article table match one of the photo_id values ​​in the photo table. - Nofate

0