Add foreign keys in migrations

Hello, I try to add foreign keys in migration. Code of migration



$this->addForeignKey('FK_user_profile',    'tbl_profile',  'user_id',   'tbl_user',  'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_books_comments',  'tbl_comments', 'book_id',   'tbl_books', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_films_comments',  'tbl_comments', 'film_id',   'tbl_films', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_games_comments',  'tbl_comments', 'game_id',   'tbl_games', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_author_comments', 'tbl_comments', 'author_id', 'tbl_user',  'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_books_likes',     'tbl_likes',    'book_id',   'tbl_books', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_games_likes',     'tbl_likes',    'game_id',   'tbl_games', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_user_likes',      'tbl_likes',    'user_id',   'tbl_user',  'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_games_screens',   'tbl_screens',  'game_id',   'tbl_games', 'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_feed_user_1',     'tbl_relator',  'user_id',   'tbl_user',  'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_feed_user_2',     'tbl_relator',  'feed_id',   'tbl_feed',  'id', 'CASCADE', 'CASCADE');

        $this->addForeignKey('FK_films_likes',     'tbl_likes',    'film_id', '  tbl_films', 'id', 'CASCADE', 'CASCADE');

The last foreig key adding fails with the next error:

General error: 1005 Can't create table 'chooseone.#sql-47b_41' (errno: 150). The SQL statement executed was: ALTER TABLE `tbl_likes` ADD CONSTRAINT `FK_films_likes` FOREIGN KEY (`film_id`) REFERENCES `  tbl_films` (`id`) ON DELETE CASCADE ON UPDATE CASCADE'

And I cant get where is my problem? The types of fields identical to the types of primary keys(INT(11)). Can somebody help me?

You have a bunch of extra spaces at the front of tbl_films:



$this->addForeignKey('FK_films_likes',     'tbl_likes',    'film_id', '  tbl_films', 'id', 'CASCADE', 'CASCADE');

thanks for help. I need be more attentive :rolleyes: