MySQL non primary foreign key

前端 未结 3 1691
误落风尘
误落风尘 2020-12-17 04:05

I\'m a bit of a newbie and I can\'t get my head around primary keys as foreign keys. To me, foreign keys are meant to connect two rows of a table together. Therefore, it wou

3条回答
  •  暖寄归人
    2020-12-17 04:29

    I think you can have the foreign key point to any column (or columns), if there is an index created with those columns at the beginning.

    Try executing

    CREATE INDEX user_username_idx ON user(username);
    

    and then creating your foreign key should work.

提交回复
热议问题