28

can not add the NOT NULL constraint

 3 years ago
source link: https://www.codesd.com/item/can-not-add-the-not-null-constraint.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

can not add the NOT NULL constraint

advertisements

I have a table called Person in MySQL. There is a column called username. I want to add NOT NULL constraint to this column using the following:

ALTER TABLE Person MODIFY username VARCHAR(32) NOT NULL;

But it failed and reported error as:

Error Code: 1265. Data truncated for column 'username' at row 1

Why can't I change this column to be NOT NULL?


Is it possible that you already have NULL values for username stored in your table? Then you would get an error as you are creating an inconsistency within your table.

Tags mysql

Related Articles

Cassandra: Can not use the 'NOT NULL' constraint when creating the array

I see many examples on here that create tables using the NOT NULL constraint. Ironically I can't seem to do the same. This is the cql command I use : CREATE TABLE activities_dev (activity_id uuid ,actor_id bigint NOT NULL, actor_appid bigint NOT NULL

The Django NOT NULL constraint failed userprofile.user_id when downloading a file

I am new to Django trying to practice a simple projects a user registers (using django registration-redux), uploads some file and then s/he is provided with a list of her files, being download able. Here are my models.py, forms.py and views respectiv

django.db.utils.IntegrityError: The NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD

I wanna add imagefield to my models.py and upload in my media_cdn directory but when i migrate to base my model.py he give this error django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD Output fro

What is the origin of IntegrityError: did not the NOT NULL constraint fail?

I'm doing the polls apps in Django Documentation: Writing your first Django app, part 2. While working with Database API, I've found an IntegrityError. polls/models.py class Question(models.Model): question_text=models.CharField(max_length=200) pub_d

The SQLite NOT NULL constraint does not work with INSERT OR IGNORE

I am with Python 2.7 and SQLite3. Here is the code: #!/usr/bin/env python import sqlite3 conn = sqlite3.connect('example.db') c = conn.cursor() c.execute('''CREATE TABLE stocks (transctionid text not null collate nocase primary key, trans text, symbo

How to check if the NOT NULL constraint exists

I am modifying a SQL table through C# code and I need to drop a NOT NULL constraint if it exists. How do I check to see if it exists first? select is_nullable from sys.columns where object_id = OBJECT_ID('tablename') and name = 'columnname';

SQL: NOT NULL constraint on a set of columns

This question already has an answer here: NOT NULL constraint over a set of columns 2 answers Consider the following table: CREATE TABLE user( first_name text, last_name text, ... ) I would like to be able to add users with either a first name, a las

SQL Not Null constraint on entire table

I was wondering if there is any way to make a single Not Null constraint that could apply to all the attributes in my table. I know I could add one to each line, but I am just trying to learn to be more efficient. I tried searching online and I didn'

Django Integrity Error - NOT NULL constraint failed: zdorovo_page.category_id

While working with Django, I created an app which shows different categories. Click on any one of them it opens up a window showing all the pages related to it . On the same window you have the option to add a new page to that particular category. I

Rails - Save objects with a NOT NULL constraint

I have a model called Issue that has the following database structure : class CreateIssues < ActiveRecord::Migration def change create_table :issues do |t| t.string :path, null: false t.string :filename, null: false t.string :name, null: false t.stri

Violation not null constraint. With a foreign key (not user) when trying to publish in Django Rest Framework

This problem is commented in the whole Internet, but I don't know why, it's almost always with the user. In my case, the problem is not with the User. I have this model: class DocumentDetail(models.Model): date = models.DateTimeField(_('date'), auto_

NOT NULL Constraint Failed for SQLalchemy Model

I have recently started working with database. I am trying to set up a model using SQLalchemy. The models.py and database.py are shown as below: #models.py import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base Base = declara

Linq - How can we add the contents of two lists

I have two IEnumberable<double> list. How can i add the each value of one list to the value in the same position in the other list using Linq?You can use Enumerable.Zip to do this: var results = first.Zip(second, (f,s) => f+s); Note that, if the

The NOT NULL constraint applies only to new lines

I will try to present the situation as a minimal example: Say we have a table of tickets, defined as follows: CREATE TABLE ticket_id_list ( ticket_id NUMBER, issued_to VARCHAR2(100), CONSTRAINT ticket_id_list_pk PRIMARY KEY (ticket_id) ); The system

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK