7 examples of 'django delete database' in Python

Every line of 'django delete database' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
271def _destroy_test_db(self, test_database_name, verbosity):
272 """
273 Internal implementation - remove the test db tables.
274 """
275 # Remove the test database to clean up after
276 # ourselves. Connect to the previous database (not the test database)
277 # to do so, because it's not allowed to delete a database while being
278 # connected to it.
279 with self.connection._nodb_connection.cursor() as cursor:
280 # Wait to avoid "database is being accessed by other users" errors.
281 time.sleep(1)
282 cursor.execute("DROP DATABASE %s"
283 % self.connection.ops.quote_name(test_database_name))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

36def __del__(self):
37 self._db_connection.close()
21@task
22def remove_db(djangoenv='develop'):
23 """ Remove ``db.sqlite3`` if it exists. """
24 if djangoenv == 'sqlite_develop':
25 if exists(DB_FILE):
26 remove(DB_FILE)
27 else:
28 _managepy('dbdev_destroy', djangoenv=djangoenv)
49def delete(self):
50 get_database_backend(self.__class__).delete(self.id)
53def __clean_old__(self, *args, **kwargs):
54 self.stdout.write("reset database")
55 call_command('reset_db')
56 self.stdout.write("clean old migrations")
57 os.system("rm -vrf */migrations/0*.py")
58 self.stdout.write("clean old images, packages, videos")
59 os.system("rm -vrf public/*")
8def delete():
9 c = mydb.cursor()
10 c.execute("DELETE FROM `play` WHERE 1")
11 mydb.commit()
12 c.execute("DELETE FROM `link` WHERE 1")
13 mydb.commit()
14 c.execute("DELETE FROM `performer` WHERE 1")
15 mydb.commit()
16 c.execute("DELETE FROM `classify` WHERE 1")
17 mydb.commit()
18 c.execute("DELETE FROM `cid` WHERE 1")
19 mydb.commit()
20 print("删除成功")
244def destroy_database(func=run):
245 """
246 Destroys the user and database for this project.
247
248 Will not cause the fab to fail if they do not exist.
249 """
250 with settings(warn_only=True):
251 func('dropdb %(project_name)s' % env)
252 func('dropuser %(project_name)s' % env)

Related snippets