title: Rails ActiveRecord::InvalidForeignKey in ArticlesController#destroy
body: <pre><code>ActiveRecord::InvalidForeignKey in ArticlesController#destroy
  
  SQLite3::ConstraintException: FOREIGN KEY constraint failed: DELETE FROM "articles" WHERE "articles"."id" = ?
  </code></pre>
  
  <p>I'm creating a blog app, I get this error every time I try to delete an article that has comments  in it. How can I fix it?</p>
  
  <p>Let me know what code to post and I will update the question.</p>
  
  <p>Articles controller:</p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
      def new
          @article = Article.new
      end
  
      def index
       #@articles = Article.all
       @articles = Article.paginate(:page =&gt; params[:page], :per_page =&gt; 10)
      end
  
      def show
          @article = Article.find(params[:id])
      end
  
       def create
          @article = Article.new(article_params)
  
          @article.save
          redirect_to @article
      end
  
      def edit
          @article = Article.find(params[:id])
      end
  
      def update
          @article = Article.find(params[:id])
          if @article.update(article_params)
              redirect_to @article
          else
              render 'edit'
          end
  
      end
  
      def destroy
          @article = Article.find(params[:id])
          @article.destroy
  
          redirect_to articles_path
      end
  end
  
  private
  def article_params
      params.require(:article).permit(:title, :text, :datee)
  end
  </code></pre>
  
  <p>Articles model:</p>
  
  <pre><code>class Article &lt; ApplicationRecord
      has_many :comments
      has_many :photos
  end
  </code></pre>
  
  <p>Comment model:</p>
  
  <pre><code>class Comment &lt; ApplicationRecord
    belongs_to :article
  end
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Now I have a new error</p>
  
  <pre><code>ArgumentError in ArticlesController#destroy
  
  Unknown key: :dependant. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type, :index_errors
  </code></pre>