The above exception ((1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`betterstart_test_v2`.`people_street`, CONSTRAINT `people_street_post_code_id_4496b743_fk_people_post_code_id` FOREIGN KEY (`post_code_id`) REFERENCES `people_post_code` (`id`))')) was the direct cause of the following exception:
You're seeing this error because you haveDEBUG = Truein your Django settings file. Change that toFalse, and Django will display a standard page generated by the handler for this status code.
I am trying to update the postcodes on test (the other projects use all the wards in Southend so I need to change 'Out of Area' to the correct ward.
I tried loading a corrected file but where the post codes already exist, it would not let me change them.
I then tried to delete all the postcodes to re-install them (not a happy idea as it would have a knock on effect) and got this error
Can I please amend postcodes en masse?
IntegrityError at /admin/people/post_code/
Request Method: | POST -- | -- https://betterstart-236907.appspot.com/admin/people/post_code/ 3.0.14 IntegrityError (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`betterstart_test_v2`.`people_street`, CONSTRAINT `people_street_post_code_id_4496b743_fk_people_post_code_id` FOREIGN KEY (`post_code_id`) REFERENCES `people_post_code` (`id`))') /layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/connections.py in query, line 224 /layers/google.python.pip/pip/bin/python3 3.7.10 ['/srv', '/workspace', '/layers/google.python.pip/pip/bin', '/opt/python3.7/lib/python37.zip', '/opt/python3.7/lib/python3.7', '/opt/python3.7/lib/python3.7/lib-dynload', '/layers/google.python.pip/pip/lib/python3.7/site-packages', '/opt/python3.7/lib/python3.7/site-packages'] Tue, 25 May 2021 14:04:28 +0100Traceback Switch to copy-and-paste view
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
in_execute
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/mysql/base.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/cursors.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/cursors.py
in_query
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/connections.py
inquery
The above exception ((1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`betterstart_test_v2`.`people_street`, CONSTRAINT `people_street_post_code_id_4496b743_fk_people_post_code_id` FOREIGN KEY (`post_code_id`) REFERENCES `people_post_code` (`id`))')) was the direct cause of the following exception:
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/core/handlers/exception.py
ininner
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/core/handlers/base.py
in_get_response
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/core/handlers/base.py
in_get_response
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/options.py
inwrapper
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/utils/decorators.py
in_wrapped_view
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/views/decorators/cache.py
in_wrapped_view_func
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/sites.py
ininner
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/utils/decorators.py
in_wrapper
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/utils/decorators.py
in_wrapped_view
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/options.py
inchangelist_view
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/options.py
inresponse_action
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/actions.py
indelete_selected
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/contrib/admin/options.py
indelete_queryset
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/models/query.py
indelete
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/models/deletion.py
indelete
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/models/sql/subqueries.py
indelete_batch
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/models/sql/subqueries.py
indo_query
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/models/sql/compiler.py
inexecute_sql
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
in_execute_with_wrappers
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
in_execute
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/utils.py
in__exit__
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/utils.py
in_execute
/layers/google.python.pip/pip/lib/python3.7/site-packages/django/db/backends/mysql/base.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/cursors.py
inexecute
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/cursors.py
in_query
/layers/google.python.pip/pip/lib/python3.7/site-packages/MySQLdb/connections.py
inquery
Request information
USER
tracey@test.com
GET
No GET data
POST
Variable | Value -- | -- csrfmiddlewaretoken | 'LgRgCCT1ccAYocWib9EogN8pq1i1YCUiWhapZl5u6qPPRsDBS3Dufgn8hSXvCAK3' _selected_action | '98' action | 'delete_selected' post | 'yes'FILES
No FILES data
COOKIES
Variable | Value -- | -- csrftoken | 'vtfs4lW0kNkPZXquwQMLAkZZwzG9YC8kGuyBr48te1zGsd7NdKLRzNeInqlDCAY5' sessionid | '7gllri2uld2lncym8iug3rdlwalf9v55'META
Variable | Value -- | -- CONTENT_LENGTH | '2111' CONTENT_TYPE | 'application/x-www-form-urlencoded' CSRF_COOKIE | 'vtfs4lW0kNkPZXquwQMLAkZZwzG9YC8kGuyBr48te1zGsd7NdKLRzNeInqlDCAY5' HTTP_ACCEPT | 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' HTTP_ACCEPT_ENCODING | 'gzip, deflate, br' HTTP_ACCEPT_LANGUAGE | 'en-GB,en-US;q=0.9,en;q=0.8' HTTP_CACHE_CONTROL | 'max-age=0' HTTP_COOKIE | ('csrftoken=vtfs4lW0kNkPZXquwQMLAkZZwzG9YC8kGuyBr48te1zGsd7NdKLRzNeInqlDCAY5; ' 'sessionid=7gllri2uld2lncym8iug3rdlwalf9v55') HTTP_FORWARDED | 'for="2a00:23c5:d400:8f00:917d:2430:2696:29d";proto=https' HTTP_HOST | 'betterstart-236907.appspot.com' HTTP_ORIGIN | 'https://betterstart-236907.appspot.com' HTTP_REFERER | 'https://betterstart-236907.appspot.com/admin/people/post_code/' HTTP_SEC_CH_UA | '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"' HTTP_SEC_CH_UA_MOBILE | '?0' HTTP_SEC_FETCH_DEST | 'document' HTTP_SEC_FETCH_MODE | 'navigate' HTTP_SEC_FETCH_SITE | 'same-origin' HTTP_SEC_FETCH_USER | '?1' HTTP_TRACEPARENT | '00-065b106f845a8b05b06c429a58dee306-c6838fa64a764220-00' HTTP_UPGRADE_INSECURE_REQUESTS | '1' HTTP_USER_AGENT | ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like ' 'Gecko) Chrome/90.0.4430.212 Safari/537.36') HTTP_X_APPENGINE_API_TICKET | 'ChA5ZTdhZTM4NjgyNTc2ODY3GhMIzqfR0vLk8AIVwk/oCh2uewV4' HTTP_X_APPENGINE_CITY | 'southend-on-sea' HTTP_X_APPENGINE_CITYLATLONG | '51.545927,0.707712' HTTP_X_APPENGINE_COUNTRY | 'GB' HTTP_X_APPENGINE_DEFAULT_VERSION_HOSTNAME | 'betterstart-236907.appspot.com' HTTP_X_APPENGINE_HTTPS | 'on' HTTP_X_APPENGINE_REGION | 'eng' HTTP_X_APPENGINE_REQUEST_LOG_ID | '60acf5d800ff0d2dce6986a24c0001657e62657474657273746172742d323336393037000173746167696e67000100' HTTP_X_APPENGINE_TIMEOUT_MS | '599999' HTTP_X_APPENGINE_USER_IP | '2a00:23c5:d400:8f00:917d:2430:2696:29d' HTTP_X_CLOUD_TRACE_CONTEXT | '065b106f845a8b05b06c429a58dee306/14304434785835434528' HTTP_X_FORWARDED_FOR | '2a00:23c5:d400:8f00:917d:2430:2696:29d, 169.254.1.1' HTTP_X_FORWARDED_PROTO | 'https' PATH_INFO | '/admin/people/post_code/' QUERY_STRING | '' RAW_URI | '/admin/people/post_code/' REMOTE_ADDR | '127.0.0.1' REMOTE_PORT | '54681' REQUEST_METHOD | 'POST' SCRIPT_NAME | '' SERVER_NAME | '0.0.0.0' SERVER_PORT | '8081' SERVER_PROTOCOL | 'HTTP/1.1' SERVER_SOFTWARE | 'gunicorn/20.0.4' gunicorn.socket | <socket.socket fd=10, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 8081), raddr=('127.0.0.1', 54681)> wsgi.errors | <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x3e4b977fda90> wsgi.file_wrapper | '' wsgi.input | <gunicorn.http.body.Body object at 0x3e4b977fdad0> wsgi.input_terminated | True wsgi.multiprocess | True wsgi.multithread | True wsgi.run_once | False wsgi.url_scheme | 'https' wsgi.version | (1, 0)Settings
Using settings module
Setting | Value -- | -- ABSOLUTE_URL_OVERRIDES | {} ADMINS | [] ALLOWED_HOSTS | ['betterstart-236907.appspot.com', '127.0.0.1', 'oysta.org', 'www.oysta.org', 'betterstart.oysta.org', 'betterstart-uat.appspot.com'] APPEND_SLASH | True AUTHENTICATION_BACKENDS | ['django.contrib.auth.backends.ModelBackend'] AUTH_PASSWORD_VALIDATORS | '********************' AUTH_USER_MODEL | 'auth.User' BASE_DIR | '/srv' CACHES | {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}} CACHE_MIDDLEWARE_ALIAS | 'default' CACHE_MIDDLEWARE_KEY_PREFIX | '********************' CACHE_MIDDLEWARE_SECONDS | 600 CRISPY_TEMPLATE_PACK | 'bootstrap3' CSRF_COOKIE_AGE | 31449600 CSRF_COOKIE_DOMAIN | None CSRF_COOKIE_HTTPONLY | False CSRF_COOKIE_NAME | 'csrftoken' CSRF_COOKIE_PATH | '/' CSRF_COOKIE_SAMESITE | 'Lax' CSRF_COOKIE_SECURE | False CSRF_FAILURE_VIEW | 'django.views.csrf.csrf_failure' CSRF_HEADER_NAME | 'HTTP_X_CSRFTOKEN' CSRF_TRUSTED_ORIGINS | [] CSRF_USE_SESSIONS | False DATABASES | {'default': {'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'ENGINE': 'django.db.backends.mysql', 'HOST': '/cloudsql/betterstart-236907:europe-west1:betterstart', 'NAME': 'betterstart_test_v2', 'OPTIONS': {}, 'PASSWORD': '********************', 'PORT': '', 'TEST': {'CHARSET': None, 'COLLATION': None, 'MIRROR': None, 'NAME': None}, 'TIME_ZONE': None, 'USER': 'betterstart-test'}} DATABASE_ROUTERS | [] DATA_UPLOAD_MAX_MEMORY_SIZE | 2621440 DATA_UPLOAD_MAX_NUMBER_FIELDS | 1000 DATETIME_FORMAT | 'N j, Y, P' DATETIME_INPUT_FORMATS | ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M', '%Y-%m-%d', '%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M:%S.%f', '%m/%d/%Y %H:%M', '%m/%d/%Y', '%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M:%S.%f', '%m/%d/%y %H:%M', '%m/%d/%y'] DATE_FORMAT | 'N j, Y' DATE_INPUT_FORMATS | ['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y'] DEBUG | True DEBUG_PROPAGATE_EXCEPTIONS | False DECIMAL_SEPARATOR | '.' DEFAULT_CHARSET | 'utf-8' DEFAULT_EXCEPTION_REPORTER_FILTER | 'django.views.debug.SafeExceptionReporterFilter' DEFAULT_FILE_STORAGE | 'django.core.files.storage.FileSystemStorage' DEFAULT_FROM_EMAIL | 'webmaster@localhost' DEFAULT_INDEX_TABLESPACE | '' DEFAULT_TABLESPACE | '' DISALLOWED_USER_AGENTS | [] EMAIL_BACKEND | 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST | 'smtp.sendgrid.net' EMAIL_HOST_PASSWORD | '********************' EMAIL_HOST_USER | 'apikey' EMAIL_PORT | 587 EMAIL_SSL_CERTFILE | None EMAIL_SSL_KEYFILE | '********************' EMAIL_SUBJECT_PREFIX | '[Django] ' EMAIL_TIMEOUT | None EMAIL_USE_LOCALTIME | False EMAIL_USE_SSL | False EMAIL_USE_TLS | True FILE_CHARSET | 'utf-8' FILE_UPLOAD_DIRECTORY_PERMISSIONS | None FILE_UPLOAD_HANDLERS | ['django.core.files.uploadhandler.MemoryFileUploadHandler', 'django.core.files.uploadhandler.TemporaryFileUploadHandler'] FILE_UPLOAD_MAX_MEMORY_SIZE | 2621440 FILE_UPLOAD_PERMISSIONS | 420 FILE_UPLOAD_TEMP_DIR | None FIRST_DAY_OF_WEEK | 0 FIXTURE_DIRS | [] FORCE_SCRIPT_NAME | None FORMAT_MODULE_PATH | None FORM_RENDERER | 'django.forms.renderers.DjangoTemplates' IGNORABLE_404_URLS | [] INSTALLED_APPS | ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'people.apps.PeopleConfig', 'crispy_forms', 'django_otp', 'django_otp.plugins.otp_totp', 'django_otp.plugins.otp_hotp', 'django_otp.plugins.otp_static', 'zxcvbn_password', 'jsignature'] INTERNAL_IPS | [] LANGUAGES | [('af', 'Afrikaans'), ('ar', 'Arabic'), ('ast', 'Asturian'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('dsb', 'Lower Sorbian'), ('el', 'Greek'), ('en', 'English'), ('en-au', 'Australian English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-co', 'Colombian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy', 'Frisian'), ('ga', 'Irish'), ('gd', 'Scottish Gaelic'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hsb', 'Upper Sorbian'), ('hu', 'Hungarian'), ('hy', 'Armenian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('io', 'Ido'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kab', 'Kabyle'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('mr', 'Marathi'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmål'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('uz', 'Uzbek'), ('vi', 'Vietnamese'), ('zh-hans', 'Simplified Chinese'), ('zh-hant', 'Traditional Chinese')] LANGUAGES_BIDI | ['he', 'ar', 'fa', 'ur'] LANGUAGE_CODE | 'en-us' LANGUAGE_COOKIE_AGE | None LANGUAGE_COOKIE_DOMAIN | None LANGUAGE_COOKIE_HTTPONLY | False LANGUAGE_COOKIE_NAME | 'django_language' LANGUAGE_COOKIE_PATH | '/' LANGUAGE_COOKIE_SAMESITE | None LANGUAGE_COOKIE_SECURE | False LOCALE_PATHS | [] LOGGING | {} LOGGING_CONFIG | 'logging.config.dictConfig' LOGIN_REDIRECT_URL | '/accounts/profile/' LOGIN_URL | '/people/login' LOGOUT_REDIRECT_URL | None MANAGERS | [] MEDIA_ROOT | 'media' MEDIA_URL | '/media/' MESSAGE_STORAGE | 'django.contrib.messages.storage.fallback.FallbackStorage' MIDDLEWARE | ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django_otp.middleware.OTPMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] MIGRATION_MODULES | {} MONTH_DAY_FORMAT | 'F j' NUMBER_GROUPING | 0 OTP_TOTP_ISSUER | 'Betterstart System Test' PASSWORD_HASHERS | '********************' PASSWORD_RESET_TIMEOUT_DAYS | '********************' PREPEND_WWW | False ROOT_URLCONF | 'betterstart.urls' SECRET_KEY | '********************' SECURE_BROWSER_XSS_FILTER | False SECURE_CONTENT_TYPE_NOSNIFF | True SECURE_HSTS_INCLUDE_SUBDOMAINS | False SECURE_HSTS_PRELOAD | False SECURE_HSTS_SECONDS | 0 SECURE_PROXY_SSL_HEADER | None SECURE_REDIRECT_EXEMPT | [] SECURE_REFERRER_POLICY | None SECURE_SSL_HOST | None SECURE_SSL_REDIRECT | False SENDGRID_API_KEY | '********************' SERVER_EMAIL | 'root@localhost' SESSION_CACHE_ALIAS | 'default' SESSION_COOKIE_AGE | 1209600 SESSION_COOKIE_DOMAIN | None SESSION_COOKIE_HTTPONLY | True SESSION_COOKIE_NAME | 'sessionid' SESSION_COOKIE_PATH | '/' SESSION_COOKIE_SAMESITE | 'Lax' SESSION_COOKIE_SECURE | False SESSION_ENGINE | 'django.contrib.sessions.backends.db' SESSION_EXPIRE_AT_BROWSER_CLOSE | False SESSION_FILE_PATH | None SESSION_SAVE_EVERY_REQUEST | False SESSION_SERIALIZER | 'django.contrib.sessions.serializers.JSONSerializer' SETTINGS_MODULE | 'betterstart.settings' SHORT_DATETIME_FORMAT | 'm/d/Y P' SHORT_DATE_FORMAT | 'm/d/Y' SIGNING_BACKEND | 'django.core.signing.TimestampSigner' SILENCED_SYSTEM_CHECKS | [] STATICFILES_DIRS | [] STATICFILES_FINDERS | ['django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder'] STATICFILES_STORAGE | 'django.contrib.staticfiles.storage.StaticFilesStorage' STATIC_ROOT | 'static' STATIC_URL | '/static/' TEMPLATES | [{'APP_DIRS': True, 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'OPTIONS': {'context_processors': ['django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages']}}] TEST_NON_SERIALIZED_APPS | [] TEST_RUNNER | 'django.test.runner.DiscoverRunner' THOUSAND_SEPARATOR | ',' TIME_FORMAT | 'P' TIME_INPUT_FORMATS | ['%H:%M:%S', '%H:%M:%S.%f', '%H:%M'] TIME_ZONE | 'Europe/London' USE_I18N | True USE_L10N | True USE_THOUSAND_SEPARATOR | False USE_TZ | True USE_X_FORWARDED_HOST | False USE_X_FORWARDED_PORT | False WSGI_APPLICATION | 'betterstart.wsgi.application' X_FRAME_OPTIONS | 'DENY' YEAR_MONTH_FORMAT | 'F Y'betterstart.settings
You're seeing this error because you have
DEBUG = True
in your Django settings file. Change that toFalse
, and Django will display a standard page generated by the handler for this status code.