Ticket #1398: CASCADEOption.diff
File CASCADEOption.diff, 2.5 KB (added by , 19 years ago) |
---|
-
core/management.py
159 159 # The table doesn't exist, so it doesn't need to be dropped. 160 160 db.db.rollback() 161 161 else: 162 output.append("DROP TABLE %s;" % db.db.quote_name(klass._meta.db_table)) 162 if CASCADE: 163 output.append("DROP TABLE %s CASCADE;" % db.db.quote_name(klass._meta.db_table)) 164 else: 165 output.append("DROP TABLE %s;" % db.db.quote_name(klass._meta.db_table)) 163 166 164 167 # Output DROP TABLE statements for many-to-many tables. 165 168 for klass in mod._MODELS: … … 171 174 except: 172 175 db.db.rollback() 173 176 else: 174 output.append("DROP TABLE %s;" % db.db.quote_name(f.get_m2m_db_table(opts))) 177 if CASCADE: 178 output.append("DROP TABLE %s CASCADE;" % db.db.quote_name(klass._meta.db_table)) 179 else: 180 output.append("DROP TABLE %s;" % db.db.quote_name(f.get_m2m_db_table(opts))) 175 181 176 182 app_label = mod._MODELS[0]._meta.app_label 177 183 … … 872 878 'validate': validate, 873 879 } 874 880 881 CASCADE = False 882 875 883 NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'installperms', 'sqlindexes') 876 884 877 885 class DjangoOptionParser(OptionParser): … … 899 907 sys.exit(1) 900 908 901 909 def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING): 910 global CASCADE 902 911 # Parse the command-line arguments. optparse handles the dirty work. 903 912 parser = DjangoOptionParser(get_usage(action_mapping)) 904 913 parser.add_option('--settings', … … 907 916 help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".') 908 917 parser.add_option('--plain', action='store_true', dest='plain', 909 918 help='Tells Django to use plain Python, not IPython, for "shell" command.') 919 parser.add_option('--cascade', action='store_true', dest='cascade', 920 help='Tells Django to output CASCADEing DROP TABLE statements.') 910 921 options, args = parser.parse_args() 911 922 912 923 # Take care of options. … … 914 925 os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 915 926 if options.pythonpath: 916 927 sys.path.insert(0, options.pythonpath) 928 CASCADE = options.cascade 917 929 918 930 # Run the appropriate action. Unfortunately, optparse can't handle 919 931 # positional arguments, so this has to parse/validate them.