简体   繁体   中英

I got a database error when Im using Django

Nice to meet you. Im from japan and If im not using properly English,please teach me. Let me ask some questions. I created a django project,and tried this code at the terminal.

python manage.py startapp myhp

Then models.py file has created. Then I wrote some class and I tried this code at the terminal.

python manage.py startapp runserver

Then following error has occured.(I dont know which point is important,so Ill show all)

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
    self.check_migrations()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 458, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 76, in applied_migrations
    if self.has_table():
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
    return get_names(cursor)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 43, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 73, in get_table_list
    ORDER BY name""")
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 394, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.DatabaseError: file is not a database

I tried to create the following file at the same directory(hp/myhhp/test.py),and it works well.

import sqlite3

dbname = 'TEST.db'
conn = sqlite3.connect(dbname)
cur = conn.cursor()

cur.execute('SELECT * FROM persons')

for row in cur:
    print(row)

cur.close()
conn.close()

What is the point? Im looking forward to your answer.

you have to say python manage.py runserver , not python python manage.py startapp runserver:) thats why u are getting error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM