diff --git a/django/core/management.py b/django/core/management.py index 6c4a450be2..67ba07cdb9 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -480,81 +480,6 @@ def syncdb(): connection.commit() syncdb.args = '' -def has_no_records(cursor): - "Returns True if the cursor, having executed a query, returned no records." - # This is necessary due to an inconsistency in the DB-API spec. - # cursor.rowcount can be -1 (undetermined), according to - # http://www.python.org/peps/pep-0249.html - if cursor.rowcount < 0: - return cursor.fetchone() is None - return cursor.rowcount < 1 - -def database_check(app): - "Checks that everything is properly installed in the database for the given module." - from django.db import backend, connection, models - cursor = connection.cursor() - app_modules = models.get_models(app) - app_label = app_modules[0]._meta.app_label - - # Check that the package exists in the database. - cursor.execute("SELECT 1 FROM %s WHERE %s = %%s" % \ - (backend.quote_name('django_package'), backend.quote_name('label')), [app_label]) - if has_no_records(cursor): -# sys.stderr.write("The '%s' package isn't installed.\n" % app_label) - print _get_packages_insert(app_label) - - # Check that the permissions and content types are in the database. - perms_seen = {} - contenttypes_seen = {} - for klass in app_models: - opts = klass._meta - perms = _get_all_permissions(opts) - perms_seen.update(dict(perms)) - contenttypes_seen[opts.module_name] = 1 - for codename, name in perms: - cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ - (backend.quote_name('auth_permission'), backend.quote_name('package'), - backend.quote_name('codename')), (app_label, codename)) - if has_no_records(cursor): -# sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename)) - print _get_permission_insert(name, codename, opts) - cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ - (backend.quote_name('django_content_type'), backend.quote_name('package'), - backend.quote_name('python_module_name')), (app_label, opts.module_name)) - if has_no_records(cursor): -# sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name)) - print _get_contenttype_insert(opts) - - # Check that there aren't any *extra* permissions in the DB that the model - # doesn't know about. - cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ - (backend.quote_name('codename'), backend.quote_name('auth_permission'), - backend.quote_name('package')), (app_label,)) - for row in cursor.fetchall(): - try: - perms_seen[row[0]] - except KeyError: -# sys.stderr.write("A permission called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) - print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ - (backend.quote_name('auth_permission'), backend.quote_name('package'), - app_label, backend.quote_name('codename'), row[0]) - - # Check that there aren't any *extra* content types in the DB that the - # model doesn't know about. - cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ - (backend.quote_name('python_module_name'), backend.quote_name('django_content_type'), - backend.quote_name('package')), (app_label,)) - for row in cursor.fetchall(): - try: - contenttypes_seen[row[0]] - except KeyError: -# sys.stderr.write("A content type called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) - print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ - (backend.quote_name('django_content_type'), backend.quote_name('package'), - app_label, backend.quote_name('python_module_name'), row[0]) -database_check.help_doc = "Checks that everything is installed in the database for the given model module name(s) and prints SQL statements if needed." -database_check.args = APP_ARGS - def get_admin_index(app): "Returns admin-index template snippet (in list form) for the given app." from django.utils.text import capfirst @@ -1182,7 +1107,6 @@ DEFAULT_ACTION_MAPPING = { 'adminindex': get_admin_index, 'createsuperuser': createsuperuser, 'createcachetable' : createcachetable, -# 'dbcheck': database_check, 'init': init, 'inspectdb': inspectdb, 'install': install,