title: How can I correctly set 2 foreign keys constraint on this table implementing a many to many relationship between 2 tables?
body: <p>I am working on MariaDB (it is the same as working on MySQL).</p>
  <p>I have some problem trying to set 2 foreign key constraints on 2 field of a table that implements a many-to-many relation between 2 tables.</p>
  <p>So I have the following tables:</p>
  <ol>
  <li><p><strong>ACCOMODATION</strong>: each record represent an hotel and have the following fields:</p>
  <pre><code> Field                                                            Type       Null Key Default    Extra                      
   ---------------------------------------------------------------------------------------------------------------------------
   id                                                               bigint(20) unsigned NO   PRI            auto_increment             
   user_id                                                          bigint(20) unsigned NO                                             
   accomodation_name                                                varchar(100) NO                                             
   description                                                      text       YES                                            
   nation                                                           varchar(100) YES                                            
   region                                                           varchar(100) YES                                            
   province                                                         varchar(100) YES                                            
   city                                                             varchar(100) YES                                            
   stars                                                            int(10) unsigned YES                                            
   geographical_position                                            point      YES                                            
   accomodation_typological_id                                      bigint(20) unsigned YES  MUL                                       
   accomodation_service_id                                          bigint(20) YES      
  </code></pre>
  </li>
  <li><p><strong>SERVICE</strong>: where each record represent a single service provided by an hotel of the previous table:</p>
  <pre><code> Field                                                            Type       Null Key Default    Extra                      
   ---------------------------------------------------------------------------------------------------------------------------
   id                                                               bigint(20) NO   PRI            auto_increment             
   description                                                      varchar(255) NO       
  </code></pre>
  </li>
  </ol>
  <p>Then I have created an <strong>ACCOMODATION_SERVICE</strong> table that implements the many-to-many relationship between the previous 2 tables, these are the fields:</p>
  <pre><code>Field                                                            Type       Null Key Default    Extra                      
  ---------------------------------------------------------------------------------------------------------------------------
  id                                                               bigint(20) unsigned NO   PRI            auto_increment             
  accomodation_id                                                  bigint(20) unsigned NO   MUL                                       
  service_id                                                       bigint(20) unsigned NO                                             
  </code></pre>
  <p>So, into the <strong>accomodation_id</strong> field of this table I put an <strong>id</strong> of the <strong>accomodation</strong> table and into the <strong>service_id</strong> of this table I put an <strong>id</strong> of the <strong>service</strong> table.</p>
  <p>How can I correctly specify that these 2 field have to be foreign keys for the <strong>accomodation</strong> and <strong>service</strong> tables? I think that I have to specify this referential constraint.</p>