title: Postgres: Error constraint "fk" of relation "tbl" does not exist (with Yii - PHP)
body: <p>I searched for this problem. But my postgres user has enough grant and I do not think I have misspelling error. However I am newbie.</p>
  
  <p>I have this error message:</p>
  
  <pre><code>21:38:03 set search_path='public'
  21:38:03 ALTER TABLE public.tbl_user DROP CONSTRAINT "fk-user-access-user-id"
  21:38:03 ERROR: constraint "fk-user-access-user-id" of relation "tbl_user" does not exist
  </code></pre>
  
  <p>I use the PhpStorm. I just open the database view, expanded the <code>tbl_user</code> table, right click and select "drop". And I got this error in the console.
  So the above SQL command generated by the PhpStorm.</p>
  
  <p>Then I tried with these commands manually on Ubuntu:</p>
  
  <pre><code>ALTER TABLE tbl_user DROP CONSTRAINT "fk-user-access-user-id"
  ALTER TABLE "tbl_user" DROP CONSTRAINT "fk-user-access-user-id"
  </code></pre>
  
  <p>But I get the same error.</p>
  
  <p>In the PhpStorm I see this definition:</p>
  
  <pre><code>"fk-user-access-user-id" FOREIGN KEY (access_id) REFERENCES tbl_access (id)
  </code></pre>
  
  <p>The <code>tbl_access</code> table exists with the primary id key.</p>
  
  <p>I do not understand this error message, because the <code>"fk-user-access-user-id"</code> foreign key is at the <code>tbl_user</code> and so for me the <code>'relation "tbl_user" does not exist'</code> strange. I do not understand.</p>
  
  <p>I tried to find similar problem on StackOverflow, but I gave up after 20x question reading.</p>
  
  <p>By the way, the postgres code was generated by the Yii framework.</p>
  
  <pre><code>$this-&gt;addColumn('{{%user}}', 'access_id', $this-&gt;integer()-&gt;notNull()-&gt;defaultValue(1)-&gt;after('status'));
  $this-&gt;addForeignKey('fk-user-access-user-id', '{{%user}}', 'access_id', '{{%access}}', 'id');
  </code></pre>
  
  <ul>
  <li>first row mean add <code>access_id</code> column to the user table.</li>
  <li>second row: create foreign key with 'fk-user...' name on tbl_user table's access_id column references to tbl_access table's id column. </li>
  </ul>
  
  <p>So I used this PHP code to generate this SQL commands. I prefer this way because for me the migration files are very useful.</p>