title: SQLite3: ""sqlite3.OperationalError: no such column: dateandtime"" when making Primary Key?
body: <p>I'm currently trying to create a database using SQLlite3 with Python, however I'm having trouble setting up a Primary Key. I'm aware of what one is, and how it uniquely identifies the table, but I want to change it from the standard &quot;rowid&quot; it comes with to the current date. When I try to add things into the table however it comes up with this:</p>
  <pre><code>File &quot;Economic_Analyser.py&quot;, line 258, in &lt;module&gt;
      startup()
    File &quot;Economic_Analyser.py&quot;, line 243, in startup
      c.execute(&quot;INSERT INTO economicdata VALUES (dateandtime, up_GDPgrowthRate, up_GDP, up_GNP, up_GDPperCapita, up_GDPagriculture, up_GDPconstruction, up_GDPmanufacturing, up_GDPmining, up_GDPpublicadmin, up_GDPservices, up_GDPtransport, up_GDPtourism, up_UnemploymentRate, up_EmploymentRate, up_InflationRate, up_CPI, up_InterestRate, up_BalanceOfTrade, up_CurrentAccount, up_Imports, up_Exports, up_FDI, up_GovernmentSpending, up_GovernmentDebt, up_BusinessConfidence, up_Bankruptcies, up_CompetitiveRank, up_CorruptionRank, up_ConsumerConfidence, up_CorporateTaxRate, up_IncomeTaxRate)&quot;)
  sqlite3.OperationalError: no such column: dateandtime
  </code></pre>
  <p>As you can see from my actual code below, I've declared that the date is the Primary Key but cannot add the data to it. I've changed the code multiple times based on what I've seen other people do but it hasn't worked. Just to clarify this isn't all of my code - just the parts that I think matter. Any help would be appreciated!!</p>
  <pre><code>try:
          data_attempt = open(&quot;Economic_Analyser.db&quot;)
      except:
          print(&quot;- Database not found. Creating 'Economic_Analyser.db' .&quot;)
          databasevariables()
          c.execute(&quot;&quot;&quot;CREATE TABLE economicdata (
              dateandtime text NOT NULL PRIMARY KEY,
              GDPgrowthRate decimal NOT NULL,
              GDP decimal NOT NULL,
              GNP decimal NOT NULL,
              GDPperCapita decimal NOT NULL,
              GDPagriculture decimal NOT NULL,
              GDPconstruction decimal NOT NULL,
              GDPmanufacturing decimal NOT NULL,
              GDPmining decimal NOT NULL,
              GDPpublicadmin decimal NOT NULL,
              GDPservices decimal NOT NULL,
              GDPtransport decimal NOT NULL,
              GDPtourism decimal NOT NULL,
              UnemploymentRate decimal NOT NULL,
              EmploymentRate decimal NOT NULL,
              InflationRate decimal NOT NULL,
              CPI decimal NOT NULL,
              InterestRate decimal NOT NULL,
              BalanceOfTrade decimal NOT NULL,
              CurrentAccount decimal NOT NULL,
              Imports decimal NOT NULL,
              Exports decimal NOT NULL,
              FDI decimal NOT NULL,
              GovernmentSpending decimal NOT NULL,
              GovernmentDebt decimal NOT NULL,
              BusinessConfidence decimal NOT NULL,
              Bankruptcies decimal NOT NULL,
              CompetitiveRank decimal NOT NULL,
              CorruptionRank decimal NOT NULL,
              ConsumerConfidence decimal NOT NULL,
              CorporateTaxRate decimal NOT NULL,
              IncomeTaxRate decimal NOT NULL
              )&quot;&quot;&quot;)
          conn.commit()
          c.execute(&quot;&quot;&quot;CREATE TABLE users (
              username text,
              password text
              )&quot;&quot;&quot;)
          conn.commit()
          conn.close()
      if internet_access == True:
          databasevariables()
          c.execute(&quot;INSERT INTO economicdata VALUES (dateandtime, up_GDPgrowthRate, up_GDP, up_GNP, up_GDPperCapita, up_GDPagriculture, up_GDPconstruction, up_GDPmanufacturing, up_GDPmining, up_GDPpublicadmin, up_GDPservices, up_GDPtransport, up_GDPtourism, up_UnemploymentRate, up_EmploymentRate, up_InflationRate, up_CPI, up_InterestRate, up_BalanceOfTrade, up_CurrentAccount, up_Imports, up_Exports, up_FDI, up_GovernmentSpending, up_GovernmentDebt, up_BusinessConfidence, up_Bankruptcies, up_CompetitiveRank, up_CorruptionRank, up_ConsumerConfidence, up_CorporateTaxRate, up_IncomeTaxRate)&quot;)
          conn.commit()
          conn.close()
          print(&quot;- Most recent data has been saved.&quot;)
      else:
          print(&quot;- Failed.&quot;)
  
  
  def databasevariables():
      global conn
      conn = sqlite3.connect(&quot;Economic_Analyser.db&quot;)
      global c
      c = conn.cursor()
  </code></pre>